Try using Inflector::humanize(Inflector::underscore($this->name))

On Jun 10, 10:10 am, Smelly_Eddie <[EMAIL PROTECTED]> wrote:
> Ok I am trying thr humanize method, and have some troubles..
>
> My new model
>
> class CustomerProductReview extends AppModel
> {
>     var $name = 'CustomerProductReview';
>
> }
>
> My new controller
>
> class CustomerProductReviewsController extends AppController {
>
>         var $name = 'CustomerProductReviews';
>         var $uses = array('CustomerProductReview', 'Product',
> 'Rating','User');
>
>         function beforeRender(){
>                 $inf=new Inflector;
>                 $this->pageTitle= $inf->humanize($this->name).' 
> '.$this->action.'
> - .:: The GreenLife List ::. ';
>
>         }
>
> I also changed my table, and everthing read out ok in the views,
> except my page title. It is show as the model name, no spaces and
> camel cased.
>
> But the humanize method of inflections class says it expects
> $lowerCaseAndUnderscoredWord.
>
> None of the options seem to take in an CamelCasedWord  the only
> function that does is called underscore. But I want spaces, not
> underscores,
>
> Any ideas?
>
> P.S. I use cake 1.1
>
> On Jun 10, 9:37 am, grigri <[EMAIL PROTECTED]> wrote:
>
> > It works fine; looks like your variables are mixed-up.
>
> > You've got `var $friendlyName=...` in the model and `$model-
>
> > >friendlyDisplay` in the controller.
>
> > If this *still* doesn't work, try using `$this->{$this->modelClass}-
>
> > >name` first:
>
> > [1] $friendlyName does not work, $name does : variable name typo
> > [2] Neither work : model name typo [make sure the primary model is
> > first if you're using uses()]
>
> > Must say though; if you stuck to cake conventions and called your
> > model 'CustomerProductReview' (table: customer_product_reviews) then
> > it would be compatible with Inflector::humanize() which is what the
> > bake script [and scaffolding] use. Of course if your friendly name is
> > to be more complicated than simply adding spaces, this is irrelevant.
>
> > On Jun 10, 2:27 pm, Smelly_Eddie <[EMAIL PROTECTED]> wrote:
>
> > > Doesnt seem to work....
>
> > > My controller
>
> > > class CustomerproductreviewsController extends AppController {
>
> > >         var $name = 'Customerproductreviews';
> > >         var $uses = array('Customerproductreview', 'Product',
> > > 'Rating','User');
> > >         var $helpers = array('Html',
> > > 'Form','Pagination','Ajax','FlashChart');
> > >         var $components = array
> > > ('Glscore','Autoformat','RequestHandler','Upload','Pagination');
>
> > >         function beforeFilter(){
> > >                 $this->pageTitle= 
> > > $this->{$this->modelClass}->friendlyDisplay.'
> > > - .:: The GreenLife List ::. ';
>
> > >         }
> > > ....
>
> > > my model
>
> > > class Customerproductreview extends AppModel
> > > {
> > >     var $name = 'Customerproductreview';
> > >     var $friendlyName = 'Customer Product Reviews';
> > >         var $validate = array(
> > >         'title' => VALID_NOT_EMPTY,
> > >         'product' => VALID_NUMBER,
> > >         'rating' => VALID_NUMBER,
> > >         'reason' => VALID_NOT_EMPTY,
> > >     );
> > >         var $displayField = 'title';
> > >         var $recursive = 2;
> > > .....
>
> > > Am I missing something?
>
> > > On Jun 10, 8:56 am, grigri <[EMAIL PROTECTED]> wrote:
>
> > > > class Pie extends AppModel {
> > > >   var $friendlyName = 'A tasty treat!';
>
> > > >   var $actsAs = array('Tasty'); // Optional
>
> > > > }
>
> > > > class AppController extends Controller {
> > > >   function beforeFilter() {
> > > >     if (!empty($this->modelClass)) {
> > > >       $this->set('title', $this->{$this->modelClass}->friendlyName . '
> > > > - foooooooooood');
> > > >     }
> > > >   }
>
> > > > }
>
> > > > Although... some might question the wisdom of setting a view-level
> > > > parameter in the controller and the model.
>
> > > > hth
> > > > grigri
>
> > > > On Jun 10, 1:37 pm, Smelly_Eddie <[EMAIL PROTECTED]> wrote:
>
> > > > > I have always used the function below in my controllers to set the
> > > > > page's title.
>
> > > > > function beforeFilter(){
> > > > >                 $this->pageTitle= $this->name.' - .:: The GreenLife 
> > > > > List ::. ';
>
> > > > > }
>
> > > > > The problem is that some model names are concatenated due to their
> > > > > HABTM nature, like "customerproductreviews"
>
> > > > > I thought I could just set a variable in the Model like
> > > > > '$displayName',  but the controllers don't see such a variable.
>
> > > > > I know there must be a way to assign readable and formatted model
> > > > > names to use in the page title.
>
> > > > > It wold also be useful when other models read related data, the bake
> > > > > script could show "related customer reviews" in my other models,
> > > > > rather than the ugly one word name.
>
> > > > > Any help?, yes I have tried google, but what to search?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to