承接 rvanmarkus/modx-laravel-models 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rvanmarkus/modx-laravel-models

最新稳定版本:0.0.3

Composer 安装命令:

composer require rvanmarkus/modx-laravel-models

包简介

Build your application / website with help of Laravel and MODX

README 文档

README

Laravel 5 Eloquent Database models to interact with MODX database.

This package helps you build Laravel applications that queries MODX pages/content and template variables. Use all the modern and beautiful features of the Laravel framework and give your users the ease of the MODX CMS.

Installation

$ composer require rvanmarkus/modx-laravel-models

Or add this to your composer.json

"require": {
    "rvanmarkus/modx-laravel-models": "dev-master"
}

##Getting started

Connect your laravel application to the same database as MODX, and use the same encoding settings. (app/config/database.php)

Using the Rvanmarkus/Modxmodels/ModxContentModel class directly

use Rvanmarkus\Modxmodels\ModxContentModel
 
//queries directly modx_site_content table => returns title, content, author, etc 
$content = ModxContentModel::where('alias','=','/about-us')->get();   

Using your own model class that specifies a MODX template ID

Create a new PHP Class and extend the Rvanmarkus/Modxmodels/PageModel. Create a new template in MODX manager and add the new template ID to the model.

(ex. App/Books.php)

use Rvanmarkus\Modxmodels\ModxPageModel

class Books extends ModxPageModel{
    const MODX_TEMPLATE_ID = 3; // id reference of the MODX (book) template (can be founded in MODX manager / or database)
}

$book = Books::where('alias','=','/example-book')
                ->with('templateVariables');
                ->published()
                ->sortPublished()
                ->get();

//Get your template variables from the templateVariables collection;                    
$book->templateVariables->get('NameOfTemplateVariables');

Using your own model classes and scopes

If you don't want a model that is specified by a template, create a model that extends the Rvanmarkus/Modxmodels/ModxContentModel class directly without the PageModel class. This class will query all the modx_site_content data by default, according the scopes you add. See the Eloquent documentation for more information.

Template variables

You can eager load template variables by adding the 'TemplateVariables' relation (see Laravel Eloquent Docs for more information)

use Rvanmarkus/Modxmodels/ModxContentModel
        
//query content models where alias is'/about-us' and load all related template variables  
$book = Books::with('templateVariables')
            ->where('alias','=','/john-doe-the-book')
            ->published()
            ->firstOrFail();
           
//for example: query the template variable (added in the MODX manager, with input type: *checkbox*) called 'Genres'
 
$tv = $book->templateVariables->get('Genres'); //ex. ['Roman','Science Fiction'] returns a array of selected checkbox TV values

The model automatically casts certain values of your template variables to Objects. The following template variable types will be automatically casted:

  • Date
  • Text
  • checkbox (multiple values)
  • MIGX data

example:

$book->templateVariables->get('DateTemplateVariable') 
// returns Carbon DateTime Object value
    
$book->templateVariables->get('MIGXTemplateVariable') 
// returns PHP Object value

$book->templateVariables->get('CheckboxTemplateVariable') 
// returns PHP Array value

$book->templateVariables->get('TextTemplateVariable') 
// returns string value

统计信息

  • 总下载量: 32
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 14
  • Watchers: 4
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固