本文整理汇总了PHP中AppModel::hasField方法的典型用法代码示例。如果您正苦于以下问题:PHP AppModel::hasField方法的具体用法?PHP AppModel::hasField怎么用?PHP AppModel::hasField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppModel
的用法示例。
在下文中一共展示了AppModel::hasField方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hasField
/**
* Se sobre escribio el metodo hasField para que el paginator ordenara por cantidad
* @param mixed $name
* @param bool $checkVirtual
*
* @return bool|mixed
*/
function hasField($name, $checkVirtual = false)
{
if ($name == "cantidad") {
return true;
}
return parent::hasField($name, $checkVirtual);
}
示例2: main
function main()
{
if (empty($this->args)) {
return $this->err('Usage: ./cake fixturize <table>');
}
if ($this->args[0] == '?') {
return $this->out('Usage: ./cake fixturize <table> [-force] [-reindex]');
}
$options = array('force' => false, 'reindex' => false);
foreach ($this->params as $key => $val) {
foreach ($options as $name => $option) {
if (isset($this->params[$name]) || isset($this->params['-' . $name]) || isset($this->params[$name[0]])) {
$options[$name] = true;
}
}
}
foreach ($this->args as $table) {
$name = Inflector::classify($table);
$Model = new AppModel(array('name' => $name, 'table' => $table));
$file = sprintf('%stests/fixtures/%s_fixture.php', APP, Inflector::underscore($name));
$File = new File($file);
if ($File->exists() && !$options['force']) {
$this->err(sprintf('File %s already exists, use --force option.', $file));
continue;
}
$records = $Model->find('all');
$out = array();
$out[] = '<?php';
$out[] = '';
$out[] = sprintf('class %sFixture extends CakeTestFixture {', $name);
$out[] = sprintf(' var $name = \'%s\';', $name);
$out[] = ' var $records = array(';
$File->write(join("\n", $out));
foreach ($records as $record) {
$out = array();
$out[] = ' array(';
if ($options['reindex']) {
foreach (array('old_id', 'vendor_id') as $field) {
if ($Model->hasField($field)) {
$record[$name][$field] = $record[$name]['id'];
break;
}
}
$record[$name]['id'] = String::uuid();
}
foreach ($record[$name] as $field => $val) {
$out[] = sprintf(' \'%s\' => \'%s\',', addcslashes($field, "'"), addcslashes($val, "'"));
}
$out[] = ' ),';
$File->write(join("\n", $out));
}
$out = array();
$out[] = ' );';
$out[] = '}';
$out[] = '';
$out[] = '?>';
$File->write(join("\n", $out));
$this->out(sprintf('-> Create %sFixture with %d records (%d bytes) in "%s"', $name, count($records), $File->size(), $file));
}
}
示例3: beforeSave
/**
* Set current language
*
* @param AppModel $Model
*/
public function beforeSave(&$Model) {
$settings = $this->settings[$Model->alias];
$language = Configure::read('Config.language');
if ($Model->hasField($settings['languageField'])) {
$Model->set(array($settings['languageField'] => $language));
}
}
示例4: beforeSave
/**
* beforeSave callback, initializes created_by or modified_by field values
*
* @param AppModel $Model
* @return boolean
* @access public
*/
public function beforeSave($Model)
{
$field = $Model->exists() ? 'modified_by' : 'created_by';
if ($Model->hasField($field)) {
$Model->set($field, $this->_getUserId());
$this->_addToWhitelist($Model, $field);
}
return true;
}
示例5: setup
/**
* Behavior setup
*
* @param AppModel $Model
* @param array $config
* @return void
* @access public
*/
public function setup($Model, $config = array())
{
$config = array_merge($this->_defaults, $config);
$config['label'] = (array) $config['label'];
$fields = $config['label'] + (array) $config['slug'];
foreach ($fields as $field) {
if (!$Model->hasField($field)) {
return trigger_error('SluggableBehavior: missing field ' . $field . ' in model ' . $Model->name, E_USER_ERROR);
}
}
$this->settings[$Model->alias] = $config;
}
示例6: generatetreelist
/**
* A convenience method for returning a hierarchical array used for HTML select boxes
*
* @param AppModel $Model Model instance
* @param mixed $conditions SQL conditions as a string or as an array('field' =>'value',...)
* @param string $keyPath A string path to the key, i.e. "{n}.Post.id"
* @param string $valuePath A string path to the value, i.e. "{n}.Post.title"
* @param string $spacer The character or characters which will be repeated
* @param integer $recursive The number of levels deep to fetch associated records
* @return array An associative array of records, where the id is the key, and the display field is the value
* @access public
* @link http://book.cakephp.org/view/1348/generatetreelist
*/
function generatetreelist(&$Model, $conditions = null, $keyPath = null, $valuePath = null, $spacer = '_', $recursive = null)
{
$overrideRecursive = $recursive;
extract($this->settings[$Model->alias]);
if (!is_null($overrideRecursive)) {
$recursive = $overrideRecursive;
}
if ($keyPath == null && $valuePath == null && $Model->hasField($Model->displayField)) {
$fields = array($Model->primaryKey, $Model->displayField, $left, $right);
} else {
$fields = null;
}
if ($keyPath == null) {
$keyPath = '{n}.' . $Model->alias . '.' . $Model->primaryKey;
}
if ($valuePath == null) {
$valuePath = array('{0}{1}', '{n}.tree_prefix', '{n}.' . $Model->alias . '.' . $Model->displayField);
} elseif (is_string($valuePath)) {
$valuePath = array('{0}{1}', '{n}.tree_prefix', $valuePath);
} else {
$valuePath[0] = '{' . (count($valuePath) - 1) . '}' . $valuePath[0];
$valuePath[] = '{n}.tree_prefix';
}
$order = $Model->alias . '.' . $left . ' asc';
$results = $Model->find('all', compact('conditions', 'fields', 'order', 'recursive'));
$stack = array();
foreach ($results as $i => $result) {
while ($stack && $stack[count($stack) - 1] < $result[$Model->alias][$right]) {
array_pop($stack);
}
$results[$i]['tree_prefix'] = str_repeat($spacer, count($stack));
$stack[] = $result[$Model->alias][$right];
}
if (empty($results)) {
return array();
}
return Set::combine($results, $keyPath, $valuePath);
}
示例7: resetSlugs
/**
* resetSlugs method
*
* Regenerate all slugs. On large dbs this can take more than 30 seconds - a time limit is set to allow a minimum
* 100 updates per second as a preventative measure.
*
* @param AppModel $model
* @param array $conditions
* @param int $recursive
* @return bool true on success false otherwise
* @access public
*/
function resetSlugs(&$model, $conditions = array(), $recursive = -1)
{
extract($this->settings[$model->alias]);
if (!$model->hasField($slugField)) {
return false;
}
$fields = array_merge((array) $model->primaryKey, $label);
$sort = $model->displayField . ' ASC';
$count = $model->find('count');
set_time_limit(max(30, $count / 100));
foreach ($model->find('all', compact('conditions', 'fields', 'sort', 'recursive')) as $row) {
$model->create();
$model->save($row);
}
return true;
}
示例8: resetSlugs
/**
* resetSlugs method
*
* Regenerate all slugs. On large dbs this can take more than 30 seconds - a time limit is set to allow a minimum
* 100 updates per second as a preventative measure.
*
* @param AppModel $Model
* @param array $conditions
* @param int $recursive
* @return bool true on success false otherwise
* @access public
*/
public function resetSlugs(&$Model, $params = array())
{
$recursive = -1;
extract($this->settings[$Model->alias]);
if ($notices && !$Model->hasField($slugField)) {
return false;
}
$defaults = array('page' => 1, 'limit' => 100, 'fields' => array_merge(array($Model->primaryKey, $slugField), $label), 'order' => $Model->displayField . ' ASC', 'conditions' => array(), 'recursive' => $recursive);
$params = array_merge($defaults, $params);
$count = $Model->find('count', compact('conditions'));
$max = ini_get('max_execution_time');
if ($max) {
set_time_limit(max($max, $count / 100));
}
while ($rows = $Model->find('all', $params)) {
foreach ($rows as $row) {
$Model->create();
$Model->save($row, true, array($slugField));
}
$params['page']++;
}
return true;
}
示例9: generatetreelist
/**
* A convenience method for returning a hierarchical array used for HTML select boxes
*
* @param AppModel $model
* @param mixed $conditions SQL conditions as a string or as an array('field' =>'value',...)
* @param string $keyPath A string path to the key, i.e. "{n}.Post.id"
* @param string $valuePath A string path to the value, i.e. "{n}.Post.title"
* @param string $spacer The character or characters which will be repeated
* @param integer $recursive The number of levels deep to fetch associated records
* @return array An associative array of records, where the id is the key, and the display field is the value
* @access public
*/
function generatetreelist(&$model, $conditions = null, $keyPath = null, $valuePath = null, $spacer = '_', $recursive = -1)
{
extract($this->settings[$model->name]);
if ($keyPath == null && $valuePath == null && $model->hasField($model->displayField)) {
$fields = array($model->primaryKey, $model->displayField, $left, $right);
} else {
$fields = null;
}
if ($keyPath == null) {
$keyPath = '{n}.' . $model->name . '.' . $model->primaryKey;
}
if ($valuePath == null) {
$valuePath = array('{0}{1}', '{n}.tree_prefix', '{n}.' . $model->name . '.' . $model->displayField);
} elseif (is_string($valuePath)) {
$valuePath = array('{0}{1}', '{n}.tree_prefix', $valuePath);
} else {
$valuePath[0] = '{' . (count($valuePath) - 1) . '}' . $valuePath[0];
$valuePath[] = '{n}.tree_prefix';
}
$results = $model->findAll($conditions, $fields, $left, null, null, $recursive);
$stack = array();
foreach ($results as $i => $result) {
while ($stack && $stack[count($stack) - 1] < $result[$model->name][$right]) {
array_pop($stack);
}
$results[$i]['tree_prefix'] = str_repeat($spacer, count($stack));
$stack[] = $result[$model->name][$right];
}
return Set::combine($results, $keyPath, $valuePath);
}