• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

kabasakalis/yii-ajax-crud-behavior: Single Page CRUD operations on ActiveRecord ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

kabasakalis/yii-ajax-crud-behavior

开源软件地址:

https://github.com/kabasakalis/yii-ajax-crud-behavior

开源编程语言:

JavaScript 83.0%

开源软件介绍:

AjaxCrudBehavior

Single Page CRUD operations on ActiveRecord models with controller behavior inherited AJAX actions

© 2013 Spiros Kabasakalis

The MIT License (MIT)

AjaxCrudBehavior

LIVE DEMO

Overview

Create, update and view details of records in a fancybox pop up. Single and bulk deletions with modal dialog prompt (noty plugin). This is actually a complete rewrite of my ajaxcrudgiitemplate extension. Instead of gii generated files,I wrote a reusable behavior that adds controller actions and eliminates repetition of code across different controllers.Javascript has been moved to a js file resulting in cleaner code.

##Requirements Yii 1.1.12 or above,may work with older versions too.

Setup.

  • Copy js_plugins folder in webroot folder.I don't like publishing assets.I register css and jss straight from a webroot subfolder.
  • Copy css folder with icons to webroot.
  • Copy behaviors folder containing AjaxCrudBehavior.php class file to protected folder.
  • Copy BootPager.php and BaseController.php to components folder.
  • Prepare the database table for your ActiveRecord model,say Product.(example product.sql provided).
  • Create the model ActiveRecord class file that corresponds to product table,(example Product.php). The only requirement is that it includes a search function that returns a CActiveDataProvider instance to populate CGridView:
public function search($pagination)
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.
		$criteria=new CDbCriteria;

       //example,fill in with your model property names.
		$criteria->compare('id',$this->id,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('price',$this->price,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
            'pagination' => array(
            'pageSize' =>$pagination,
                      ),
		));
	}
  • Write a controller for the model.The only requirement for the controller is that includes the code below and extends from BaseController.
class [ MODEL CLASS NAME ] Controller extends BaseController
{
public function init(){
   $this->ajaxCrudBehavior->register_Js_Css();
   parent::init();
}

   public function behaviors()
      {
          return array(
                  'ajaxCrudBehavior' => array('class' => 'application.behaviors.AjaxCrudBehavior',
                  'modelClassName' =>'[MODEL CLASS NAME(ex.Product)]',
                  'form_alias_path' =>'[FORM PATH ALIAS (ex.application.views.product._form)]',
                  'view_alias_path' =>'[VIEW PATH ALIAS (ex.application.views.product._view)]' ,
                  'pagination'=>'10'      //page size for CGridView pagination
              )
          );
      }
...
Your controller code
...
}

Templates for the form and view files are provided,you will only need to modify property names and input fields for your specific model and copy to view folder of your controller.

  • Last,you need to configure property columns for the CGridView in admingrid.php and copy it to controller's view folder. Again,a template is provided-it's straightforward.

  • Make sure you include jquery before any other scripts.Either uncomment the relevant line in register_Js_Css() function of AjaxCrudBehavior or register it somewhwere else in your code.

  • Example files use bootstrap styled markup.Uncomment the relevant line that registers bootstrap.css in register_Js_Css() function of AjaxCrudBehavior if it's not already registered somewhere else in your application.

  • Navigate to /[controllerID]/admingrid to render the administration page.

  • Example files for model,controller,form and view files are provided.

    ##Resources

  • Fancybox

  • Noty

  • Bootstrap

  • Bootstrap extension for Yii

  • JQueryForm Plugin

  • spin.js




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap