User Profile
- User
- cornernote
- Location
- Australia
- URL
- http://mrphp.com.au
Recent Articles
unbindAll
Here is a simple way to unbind all models. Just put this function into your app_model.php
- Published by cornernote 12/10/06 - 18:04
- 20827 views
- 5 comments
Maxlength using Database Field Lengths
I wanted to have a maxlength="something" in my forms, but I needed the value to come from the database at least during development. When it goes live the data will cache so it will still be fast.
- Published by cornernote 11/27/06 - 00:34
- 8118 views
- 1 comment







function __getFolder(&$model, $record) {
extract($this->settings[$model->name]);
return $baseDir .'/'. Inflector::camelize($model->name) .'/'. $record[$model->primaryKey] . '/';
}
function __getFullFolder(&$model, $field) {
extract($this->settings[$model->name]);
return WWW_ROOT . IMAGES_URL. $baseDir .DS. Inflector::camelize($model->name) .DS. $model->id .DS;
}
Where do $baseDir and IMAGES_URL get defined?
This would allow the use of the far superior imagemagick over gd, and would also be easily extend with other image lib functions if needed.
p.s. Awesome code, thanks!
The original can be downloaded from here:
http://othy.wordpress.com/2006/06/03/unbind-all-associations-except-some/
Model Class:
<?php
function unbindAll($params = array())
{
foreach($this->__associations as $ass)
{
if(!empty($this->{$ass}))
{
$this->__backAssociation[$ass] = $this->{$ass};
if(isset($params[$ass]))
{
foreach($this->{$ass} as $model => $detail)
{
if(!in_array($model,$params[$ass]))
{
$this->__backAssociation = array_merge($this->__backAssociation, $this->{$ass});
unset($this->{$ass}[$model]);
}
}
}else
{
$this->__backAssociation = array_merge($this->__backAssociation, $this->{$ass});
$this->{$ass} = array();
}
}
}
return true;
}
?>
Then use it like this:
View Template:
if($othAuth->hasPermission('items/delete')){ ... }
Helper Class:
<?php
function hasPermission($val,$arg='name')
{
$perms = $this->permission($arg);
if (in_array('*',$perms))
{
return true;
}
if (in_array($val,$perms))
{
return true;
}
$vals = explode('/',$val);
$val = '';
for ($i=0; $i<count($vals); $i++)
{
if ($i)
{
$val .= '/';
}
$val .= $vals[$i];
if (in_array($val,$perms))
{
return true;
}
}
return false;
}
?>