我可以在Code Igniter中执行此操作
$this->db->select();
$this->from->('node');
if ($published == true)
{
$this->db->where('published', 'true');
}
if (isset($year))
{
$this->db->where('year >', $year);
}
$this->db->get();
Run Code Online (Sandbox Code Playgroud)
我无法在Laravel中做到这一点.伙计们,请你帮忙.
我正在为我的应用程序的数据库编写大量迁移脚本。我想为专栏添加评论,以便其他人可以轻松识别专栏的内容。一种选择是编写普通的 SQL 查询并添加注释。但是有没有一种方法可以在 Migration scipt 中添加这些注释?
$this->dbforge->add_field(array(
'post_id' => array(
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
'comment' => 'Unique post id'
),
'user_id' => array(
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
),
'group_id' => array(
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
),
'source' => array(
'type' => 'VARCHAR',
'constraint' => 20
),
'data' => array(
'type' => 'TEXT',
),
'created' => array(
'type' => 'INT',
'constraint' => 11, …Run Code Online (Sandbox Code Playgroud) 我有一个控制器,它使用$ http获取XML文件并将其解析为json对象.这是'MainCtrl'.现在我想在其他控制器中获得相同的json对象而不再通过$ http,因为我已经加载了XML.
这是我的第一个控制器
angularXML.controller('MainCtrl', ['$scope', '$http','courseDefService', function($scope, $http, courseDefService) {
$http.get(base_url + 'assets/js/angularxml/courseDef.xml').then(function(response) {
var chapters = [];
var courseDef = x2js.xml_str2json(response.data);
console.log(courseDef);
}
Run Code Online (Sandbox Code Playgroud)
这是我的第二个控制器
angularXML.controller('chapterCtrl', ['$scope', '$routeParams', function($scope, $routeParams) {
$scope.chapterNumber = $routeParams.id;
var chapter = $scope.chapterNumber - 1; /* index starts from zero */
}
Run Code Online (Sandbox Code Playgroud)
我想我需要使用工厂.但我不知道该怎么做.我尝试了一个实现,我在工厂内获取XML.但是当我调用工厂方法时,它正在执行另一个我通过控制台确认的ajax请求.
请帮忙.