dtx3006 2013-11-27 13:50
浏览 68

Codeigniter HMVC + datamapper

I'm facing a problem when I'm using datamapper with codegniter and HMVC module. It didnt work for MX_CONTROLLER .. c

I have followed these steps: http://stensi.com/datamapper/pages/installation.html I have created two modules.

Albums_model:

<?php
class albums_model extends DataMapper {

    var $has_many = array('photos_model');
    public $table = 'albums';

}
?>

And photos_model:

<?php
class photos_model extends DataMapper {

    public $table = 'photos';
    public $validation= array(
     array(
        'field' => 'title',
        'label' => 'Title',
        'rules'=>array('required')
    )
);
?>

Photos controller:

<?php
class Photos extends MX_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('photos_model');
    }

    function index()
    {
        $p=new photos_model();
        $p= $this->photos_model->get();
        print_r($p);
    }
 }
?>

Where is the problem? Can anyone help me?

By the way, is there any $belong_to option similar to cakephp?

  • 写回答

1条回答 默认 最新

  • doujionggan9570 2013-11-27 19:23
    关注

    These two lines of code are redundant.

    $p=new photos_model();
    $p= $this->photos_model->get();
    

    Based on the examples given here: http://stensi.com/datamapper/pages/gettingstarted.html

    I believe you would want to do:

    $p->get();
    

    In place of that second line.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分