Print a list of all controllers for the project? - cakephp-2.0

Is there a way to print out a list of all the controllers associated with a project? I've done some searching around but haven't had a lot of luck.

Use App::objects('Controller') to find out which Objects Controller are used within your application. Find out more about App class at http://book.cakephp.org/2.0/en/core-utility-libraries/app.html

I actually ended up doing this
$controllpull = App::objects('Controller');
Then you can just do a print_r($controllpull);

Related

I need some help manipulating a string in Ruby

I have this string 'custom_controller'.
I need to get it to this 'CustomController'.
It's from the required file name and the class name inside is needed.
To cut to the chase, the code is here.
It is a project that comes from the Rack tutorials on Github. rack/rack/wiki/Tutorials
But rather than just name them custom.rb and class Custom, I want it more like a Rails app without requiring Rails or any of the gems that come with Rails except maybe Rack.
This is not a Rails app. This is not even a Sinatra or Padrino app. It's just a home brew web framework using Rack.
You can use plain ruby to build your own camelize method.
def camelize(string)
string.split('_').map(&:capitalize).join
end
This would also work:
"custom_controller".gsub(/_*([a-z]+)/i) {$1.capitalize}
And is closer to the way Rails handles this issue. I'd suggest you look at the Rails code as it also handles some variations on the simple case you quote. For example, how would you handle name spaced controllers 'foo/custom_controller'?
The desired result is just the camel case representation of the source string. You can try to use 'custom_controller'.camelize.
You could get it as 'CustomController' by doing following :
'custom_controller'.split('_').collect{|x| x.camelize}.join
If you want to use this as class you could do following :
'custom_controller'.split('_').collect{|x| x.camelize}.join.constantize
constantize is basically used to convert any string to class.
But I am not sure whether that works for controller. You can read more about it here
Read more about camelize here.

Finding an solution on Views?

Hi everyone I am developing an website and I wanna use one block similarly to this link https://careers.mit.edu/#block-views-facts-block.
Which it contains the flowing text and i liked it by the way so i wanna do it similar to this.
Would be grateful if any one suggest me the right way to do it.
they are using Drupal Views to output a text blocks, after custom animate function in JS/JQuery
check this file
https://careers.mit.edu/sites/default/files/js_injector/js_injector_2.js
Drupal.Careers.scrolling_text_animate
and few more to handle text position ...
animate function is quite big, you can do similar or look for an JQ plugin

Understanding ons.slidingMenu variable in onsen-ui framework

please explain me in a words why it works perfect when I call
ons.slidingMenu.toggleMenu()
having at the same time myMenu as variable of
<ons-sliding-menu ....var="myMenu">
I mean I should call myMenu.toggleMenu(), not ons.slidingMenu.toggleMenu() ....
I think that ons.slidingMenu is defined deep inside onsen. Where I could read about all this hidden vars? (I've found nothing about it in onsen-ui site)
Thanks!
It's the same object, but I would advice using the one you get using the var="..." attribute.
Actually if you have a navigator you get an ons.navigator variable as well. If you have many of the same type of component it will refer to the one that was parsed most recently.

How to create a simple 'Hello World' with two language in cakephp?

i have been searching for easy sample of multi language project in cakephp.
but i can't find this sample. i think should use i18n but i can't use.
can help me for this sample?
Basically you've to combine the link that Matt gave you, which is the way to use translation on static texts on your website for ex. like links "More..." etc, with Translate behavior, which as mentioned before is based of i18n and will give you the possibility to use Translation on your models stored in DB.
Please check this page in book: http://book.cakephp.org/1.3/en/The-Manual/Core-Behaviors/Translate.html hope this will be helpfull
you need to create a controller in app>controllers> (create the controller here)
Then you need to declare an action in the controller.
For example in the examples_controllers.php controller file:
ExamplesController extends AppController{
function anyName() {
var $uses = null;
$this->set('hello', "hello world");
}
}
to call this from view:
create a folder under views (make sure give the name same as the controller name)
For above controller, the folder name will be examples.
Then in the folder, create "any_Name.ctp" file. (the name should be as the action name)
In that ctp file just call that variable hello. That will do.
I surfed through the web and got a complete solution in here, on my site:
http://www.getallthing.com/cake-php-hello-world/
Best of luck! Cheers!

How do I code a MVC3 Helper

I’ve just build my first Helper in MVC, it’s very basic and just displays a string where ever I use it. So it’s a .cshtml file in my App_Code folder, I think that is how it's supposed to be set up, with the following code in it,
#helper DisplaySelect() {
#:This text is coming from an helper class.
}
Now I am a wiz with helpers how do I make it do things. E.g.. say I want it to query the database and display something, I would normally do that work in my controller. How do I do that with helpers, do I create a helper controller and then treat the helper like a partial view???
Any help would be greatly appreciated.
Cheers,
Mike.
Thanks guys,
I’ve asked that question before Shark “Why would you use a helper and not a partial view” the answer I got there was a partial view is more for just displaying common HTML where as a Helper can have a bunch of code in it and do all kinds of great processing stuff. Now it seems that’s not true and they are pretty much the same thing, in some respect, except in Link664’s case!
I like what you’re saying Link664 that makes sense as it cleans up the code nicely.
What I was going to do was try and populate a drop down list in a helper and then use it in multiple places, but from my research today that’s not what helpers are for.
Cheers,
Mike.
I'm a bit confused by what you want to do and why you want to do it but I'll give it a go. As you mentioned, you would normally do that work in your controller. It is very poor design to make database calls from a partial view/html helper created client-side.
The #helper syntax is to be used only for simplifying view code, not for implementing code that should be in the controllers or models in the view. See this article for a better idea of when you should be using them.
As for your example, I recommend you pass the data that you want from your controller and create an extension method on HtmlHelper to render it in your view. For example if you wanted to display a list of the most recent 10 posts on your view:
public static HtmlString RecentPostsDisplay(this HtmlHelper html, string name,
List<Post> values, object htmlAttributes)
{
var tag = new TagBuilder("ul");
...
//build list content by looping through values and adding to TagBuilder
...
return new HtmlString(tag.ToString(TagRenderMode.SelfClosing));
}
and in your controller
public ActionResult Blah()
{
ViewBag.posts = _db.GetMostRecentPosts();
return View();
}
Then in your view you can put
#Html.RecentPostsDisplay(ViewBag.RecentPosts)
Hopefully that is what you are looking for, if not update your question so it's not so ambiguous and I'll try again!

Resources