这是我的模特:
<?php
class Dbtest extends CI_Model {
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function getAll() {
parent::Model();
$this->db->select('title, content');
$this->db->from('posts');
$this->db->where('post_id', 1);
$q = $this->db->get();
if($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Dbtest extends CI_Controller {
function index() {
$this->load->model('dbtest');
$data['rows'] = $this->dbtest->getAll();
$this->load->view('dbtest', $data);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的看法
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML …Run Code Online (Sandbox Code Playgroud) 我可能错过了一些非常明显的东西.我试图在Cake中将多个表连接在一起,但我只从第一个表中获取字段.请考虑以下代码..
$joins = array();
$joins[] = array(
'table' => 'products',
'alias' => 'Product',
'type' => 'LEFT',
'conditions' => array(
'Device.id = Product.device_id'
)
);
$joins[] = array(
'table' => 'pricepoints',
'alias' => 'Pricepoints',
'type' => 'LEFT',
'conditions' => array(
'Pricepoints.product_id = Product.id'
)
);
$all_products = $this->Device->find('all', array("joins" => $joins);
Run Code Online (Sandbox Code Playgroud)
这将返回以下SQL
SELECT `Device`.`id`, `Device`.`manufacturer_id`, `Device`.`name`, `Device`.`type_id`, `Manufacturer`.`id`, `Manufacturer`.`name` FROM `devices` AS `Device` LEFT JOIN products AS `Product` ON (`Device`.`id` = `Product`.`device_id`) LEFT JOIN pricepoints AS `Pricepoints` ON (`Pricepoints`.`product_id` = `Product`.`id`) …Run Code Online (Sandbox Code Playgroud) 我对Jamie Rumbelow的MY_Model和模型有一个疑问.MY_Model提供一个保护变量,该变量保存表的名称.我想使用它,但我希望我的模型能够处理3个表.所以我想我的问题是模型可以处理多个表吗?这样做是好习惯还是每个数据库表都有一个模型更好?
我有一个Model with Date字段和Store,它从XML加载,其日期字段与字符串相同.sencha会自动将其解析为Date还是我需要手动执行此操作?
Ext.regModel('News', {
idProperty: 'Id',
fields: [
{ name: 'Id', type: 'int' },
{ name: 'Title', type: 'string' },
{ name: 'PostedOn', type: 'date' },
{ name: 'PostedBy', type: 'string' },
{ name: 'Details', type: 'string' }
]
});
var newsRemoteStore = new Ext.data.Store({
model: 'News',
sorters: [{
property: 'PostedOn',
direction: 'DESC'
}],
proxy: {
type: 'ajax',
url: BaseURL + 'News.php',
reader: {
type: 'xml',
root: 'News',
record: 'New'
}
},
getGroupString: function(record) {
if (record && record.data.PostedOn) …Run Code Online (Sandbox Code Playgroud) 出于某种原因,我不能按照我的意愿使用此验证,特别是使用密码minLength字段.
其他一切都很好(甚至用户名的minLength工作).出于某种原因,当我在密码字段中添加相同的minLength规则时,它只是忽略它,当我实际输入密码时,它告诉我需要输入密码:
var $validate = array(
'email' => array(
'email' => array(
'rule' => array('email', true),
'required' => true,
'allowEmpty' => false,
'message' => 'Please enter a valid email address'
),
'isUnique' => array(
'rule' => 'isUnique',
'message' => 'This email is already in use'
)
),
'username' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'required' => true,
'message' => 'Please enter a valid username'
),
'allowedCharacters' => array(
'rule' => '/^[a-zA-Z]+[0-9]*$/',
'message' => 'Please enter a valid username' …Run Code Online (Sandbox Code Playgroud) 我现在正在使用backbonejs mvc javascript库开发一个死的简单应用程序.只是为了表明这里的简单是html
<div class="container">
<div>
<label>
Name:
<input id="txtName" type="text" title="Type your name please" /></label>
<button id="btnSubmit" type="button" value="Submit">
Submit</button>
</div>
<div id="names">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这就是我想要的应用程序.
用户键入名称(或一些字母数字字符串)并单击提交.
验证后的值(他们称之为模型我认为)将被发送到宁静的服务.
Service将返回相同的字符串以及数据库保存操作的状态.
我现在很困惑click事件将在哪里处理(在模型中?),之后应该在何处调用render方法?(在视图中).下面你会找到我迄今为止管理的脚本
//store a global reference to model
window["model"] = Backbone.Model.extend({
defaults: { name: "Type your name"
},
validate: function () {
}
});
Run Code Online (Sandbox Code Playgroud)
//store a global reference to view
window["view"] = Backbone.View.extend({});
Run Code Online (Sandbox Code Playgroud)
在视图中没有任何说法:(
//when every thing is ready kick of the application
$(document).ready(function () { …Run Code Online (Sandbox Code Playgroud) 如何定义模型属性的默认值?该属性DefaultValue不起作用:
[DisplayName("Infos")]
[DefaultValue("Test")]
[DataType(DataType.MultilineText)]
public object infos { get; set; }
Run Code Online (Sandbox Code Playgroud) 我在app引擎中拥有自己的User模型,该模型应具有其gravatar url的属性.但是,由于可以使用他的电子邮件地址快速计算,因此存储它没有意义.有没有办法在从数据存储区加载时自动初始化此属性?
我可以添加一个名为get_avatar_url()的方法,但是你不能在jinja2模板中调用对象的方法(据我所知),并且我不想将所有这些值单独发布到模板中.
当我在ASP.NET应用程序中创建实体模型时,它会在每个实体名称的末尾添加"s",即如果我的表名是数据库中的"SiteUser",它将成为实体模型中的"SiteUsers".我该怎样预防呢?
在我的应用程序中,我有多态的想法模型,我使用不同的实体,如项目,机会等.在想法表中,它区分使用ideable_id和ideable_type
EG-对于项目ideable_id是project_id&ideable_type是'项目'EG-对于机会ideable_id是opportunity_id &ideable_type是'机会'
现在我的问题是我必须为ideabank创建想法并且ideabank不是像项目或机会那样的实体它是一个虚拟实体.那么我应该如何创建没有数据库的模型,这将给我ideable_id和ideable_type?或者在为ideabank添加想法时,我是否将这两列留空?
model ×10
cakephp ×2
codeigniter ×2
asp.net ×1
attributes ×1
backbone.js ×1
cakephp-1.3 ×1
javascript ×1
join ×1
loading ×1
php ×1
render ×1
sencha-touch ×1
store ×1
view ×1
virtual ×1