Я пытаюсь создать свой первый краб на Laravel

Я новичок в фреймворке Laravel, на этой неделе я пытаюсь создать приложение CRUD с laravel 4.x Я заканчиваю код, но мое приложение может сохранить входные данные. Вы можете помочь сломать это?
Следующие мои модули

class ModuleAdd extends BaseModel  {

protected $table = 'tab_tes';
protected $primaryKey = 'id';

public function __construct() {
parent::__construct();

}

public static function querySelect(  ){return "  SELECT tab_tes.* FROM tab_tes  ";
}
public static function queryWhere(  ){

return " WHERE tab_tes.id IS NOT NULL   ";
}

public static function queryGroup(){
return "  ";
}

чем это мой контроллер

class ModuleAddController extends BaseController {

protected $layout = "layouts.main";
protected $data = array();
public $module = 'ModuleAdd';
static $per_page    = '10';

public function __construct() {
parent::__construct();
$this->beforeFilter('csrf', array('on'=>'post'));
$this->model = new ModuleAdd();
$this->info = $this->model->makeInfo( $this->module);
$this->access = $this->model->validAccess($this->info['id']);

$this->data = array(
'pageTitle' =>  $this->info['title'],
'pageNote'  =>  $this->info['note'],
'pageModule'=> 'ModuleAdd',
'trackUri'  => $this->trackUriSegmented()
);}public function getIndex()
{
if($this->access['is_view'] ==0)
return Redirect::to('')
->with('message', SiteHelpers::alert('error',Lang::get('core.note_restric')));

// Filter sort and order for query
$sort = (!is_null(Input::get('sort')) ? Input::get('sort') : 'id');
$order = (!is_null(Input::get('order')) ? Input::get('order') : 'asc');
// End Filter sort and order for query
// Filter Search for query
$filter = (!is_null(Input::get('search')) ? $this->buildSearch() : '');
// End Filter Search for query

// Take param master detail if any
$master  = $this->buildMasterDetail();
// append to current $filter
$filter .=  $master['masterFilter'];$page = Input::get('page', 1);
$params = array(
'page'      => $page ,
'limit'     => (!is_null(Input::get('rows')) ? filter_var(Input::get('rows'),FILTER_VALIDATE_INT) : static::$per_page ) ,
'sort'      => $sort ,
'order'     => $order,
'params'    => $filter,
'global'    => (isset($this->access['is_global']) ? $this->access['is_global'] : 0 )
);
// Get Query
$results = $this->model->getRows( $params );

// Build pagination setting
$page = $page >= 1 && filter_var($page, FILTER_VALIDATE_INT) !== false ? $page : 1;
$pagination = Paginator::make($results['rows'], $results['total'],$params['limit']);$this->data['rowData']      = $results['rows'];
// Build Pagination
$this->data['pagination']   = $pagination;
// Build pager number and append current param GET
$this->data['pager']        = $this->injectPaginate();
// Row grid Number
$this->data['i']            = ($page * $params['limit'])- $params['limit'];
// Grid Configuration
$this->data['tableGrid']    = $this->info['config']['grid'];
$this->data['tableForm']    = $this->info['config']['forms'];
$this->data['colspan']      = SiteHelpers::viewColSpan($this->info['config']['grid']);
// Group users permission
$this->data['access']       = $this->access;
// Detail from master if any
$this->data['masterdetail']  = $this->masterDetailParam();
$this->data['details']      = $master['masterView'];
// Master detail link if any
$this->data['subgrid']  = (isset($this->info['config']['subgrid']) ? $this->info['config']['subgrid'] : array());
// Render into template
$this->layout->nest('content','ModuleAdd.index',$this->data)
->with('menus', SiteHelpers::menus());
}function getAdd( $id = null)
{

if($id =='')
{
if($this->access['is_add'] ==0 )
return Redirect::to('')->with('message', SiteHelpers::alert('error',Lang::get('core.note_restric')));
}

if($id !='')
{
if($this->access['is_edit'] ==0 )
return Redirect::to('')->with('message', SiteHelpers::alert('error',Lang::get('core.note_restric')));
}

$id = ($id == null ? '' : SiteHelpers::encryptID($id,true)) ;

$row = $this->model->find($id);
if($row)
{
$this->data['row'] =  $row;
} else {
$this->data['row'] = $this->model->getColumnTable('tab_tes');
}
/* Master detail lock key and value */
if(!is_null(Input::get('md')) && Input::get('md') !='')
{
$filters = explode(" ", Input::get('md') );
$this->data['row'][$filters[3]] = SiteHelpers::encryptID($filters[4],true);
}
/* End Master detail lock key and value */
$this->data['masterdetail']  = $this->masterDetailParam();
$this->data['filtermd'] = str_replace(" ","+",Input::get('md'));
$this->data['id'] = $id;
$this->layout->nest('content','ModuleAdd.form',$this->data)->with('menus', $this->menus );
}

function getShow( $id = null)
{

if($this->access['is_detail'] ==0)
return Redirect::to('')
->with('message', SiteHelpers::alert('error',Lang::get('core.note_restric')));

$ids = (is_numeric($id) ? $id : SiteHelpers::encryptID($id,true)  );
$row = $this->model->getRow($ids);
if($row)
{
$this->data['row'] =  $row;
} else {
$this->data['row'] = $this->model->getColumnTable('tab_tes');
}
$this->data['masterdetail']  = $this->masterDetailParam();
$this->data['id'] = $id;
$this->data['access']       = $this->access;
$this->layout->nest('content','ModuleAdd.view',$this->data)->with('menus', $this->menus );
}

function postSave( $id =0)
{
$trackUri = $this->data['trackUri'];
$rules = $this->validateForm();
$validator = Validator::make(Input::all(), $rules);
if ($validator->passes()) {
$data = $this->validatePost('tab_tes');
$ID = $this->model->insertRow($data , Input::get('id'));
// Input logs
if( Input::get('id') =='')
{
$this->inputLogs("New Entry row with ID : $ID  , Has Been Save Successfull");
$id = SiteHelpers::encryptID($ID);
} else {
$this->inputLogs(" ID : $ID  , Has Been Changed Successfull");
}
// Redirect after save
$md = str_replace(" ","+",Input::get('md'));
$redirect = (!is_null(Input::get('apply')) ? 'ModuleAdd/add/'.$id.'?md='.$md.$trackUri :  'ModuleAdd?md='.$md.$trackUri );
return Redirect::to($redirect)->with('message', SiteHelpers::alert('success',Lang::get('core.note_success')));
} else {
return Redirect::to('ModuleAdd/add/'.$id.'?md='.$md)->with('message', SiteHelpers::alert('error',Lang::get('core.note_error')))
->withErrors($validator)->withInput();
}

}

public function postDestroy()
{

if($this->access['is_remove'] ==0)
return Redirect::to('')
->with('message', SiteHelpers::alert('error',Lang::get('core.note_restric')));
// delete multipe rows
$this->model->destroy(Input::get('id'));
$this->inputLogs("ID : ".implode(",",Input::get('id'))."  , Has Been Removed Successfull");
// redirect
Session::flash('message', SiteHelpers::alert('success',Lang::get('core.note_success_delete')));
return Redirect::to('ModuleAdd?md='.Input::get('md'));
}

Я использую php 5.x и Apache2 с MySQL 5.x
пожалуйста помоги.

-2

Решение

Если вы новичок, то я рекомендую бросить Laravel 4 и вместо этого взять Laravel 5.

Вам также нужно немного почитать, особенно о Eloquent ORM http://laravel.com/docs/5.0/eloquent а затем RESTful контроллеры из http://laravel.com/docs/5.0/controllers#restful-resource-controllers

1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector