Let's say that I have a resource called "Resource_test". When I'm displaying that resource in Nova, that resource name (or "label") displays the name as-is which obviously isn't very user-friendly.
Is it possible to rename the "label" to "Resource Test" (without the underscore for example)?
It seems like they set the name in the file src\Nova.php on the static function resourceInformation but even though I change the name there, it doesn't seem to change the name on the site itself...
You can override the static label method within the resource class like this:
public static function label() {
return 'Your own label';
}
You'll find your resource classes in the app/Nova directory. Do not confuse these classes with the identically-named models! Adding the label method to the model will not work.
You can take a look at the Nova\src\Resource.php class to view all the options.
Related
Having pulled this codebase:
https://github.com/RedRiverSoftware/FromHeaderAttribute
after reading this:
https://river.red/binding-to-and-validating-http-headers-with-web-api-2/
I am trying to change this:
public IHttpActionResult EchoHeaders([RedRiver.FromHead.FromHeader]StandardHeaders headers)
to this:
public IHttpActionResult EchoHeaders([FromHeader]StandardHeaders headers)
Obviously, I needed to add this to the top of the controller class:
using FromHeaderAttribute.Sample.Models;
But I am getting this error:
'FromHeaderAttribute' is not an attribute class.
However, looking at the code (which I have not changed) the 'FromHeaderAttribute' class clearly inherits 'ParameterBindingAttribute' which inherits 'System.Attribute'.
What am I missing to be able to define attributes which can be used as parameter attributes without specifying their whole namespace - just like attributes such as 'FromUri' and 'FromBody'?
Turns out that naming a class 'FromHeader' and trying to use it as a parameter attribute will not get recognised. I've tried this with a number of different combinations of file, class and namespace names and it just doesn't work. The attribute class name must be anything except FromHeader.
Given the class
<?php
class NameSpace_HelloWorld_IndexController extends Mage_Core_Controller_Front_Action
{
public function sayHelloAction()
{
}
}
What should be the name of the layout file?
hello_world.xml
helloworld.xml
What should be the xml action name of the sayHelloAction?
<hello_world_index_say_hello></hello_world_index_say_hello>
<helloworld_index_sayhello>
An article on magento naming conventions would be appreciated. The examples I found only explaned the Namespace_Helloworld_IndexController::sayhello() coding style.
What should be the name of the layout file?
Anything you want. There's no enforced naming convention for the layout file — it's completely decoupled from the module name. All you need to do is specify an XML layout file name in your config.xml file. That said, the convention among the more engineering focused Magento developers is to use a lowercased version of the full module name for third party modules (namespace_helloworld.xml).
What should be the xml action name of the sayHelloAction?
The correct name for this node is the full action handle. The naming here is going to depend on how you configured your router nodes in config.xml, and how a particular URL routed itself through the system. In other words, beyond the scope of a single Stack Overflow answer.
You can peek at the full action name with the following code in your action method.
public function sayHelloAction()
{
var_dump(strToLower($this->getFullActionName()));
}
Generally speaking though, the convention is
[Route Name]_[Controller Name]_[Action Name]
Assuming you setup your route name to match your module name, that would be
route name: namespace_helloworld
controller name: index
action name: sayHello
or
namespace_helloworld_index_sayhello
NameSpace_HelloWorld_IndexControllerfile is incorrect controller class name
controller class name should be ended by 'Controller', Controllerfile is not allowed
about layout file: you should define the name of layout file in config.php
about handlers: if you use camelCase, you just need to lowercase the method name and remove 'action' from the end, for example getSuperDataAction will be < route>_< controller>_getsuperdata
I have both web form and MVC3 at my web application. I have a function which works fine under web form. I tried to reference it in MVC controller.Because I need this function's return value in my MVC controller.So I put function's inherits namespace under MVC controller. But it says 'The name 'functionname' does not exist in the current context.'
For example: I have a function name 'getClaimValue' under PortalUserControl:
namespace Site.Control {public class PortalUserControl:PortalViewUserControl{ public string getClaimValue(){...}}}
so I put using Site.Control under my MVC controller
using Site.Control ; namespace Site.Areas.Account.Controllers{public class AccountController:Controller{[HttpGet]public ActionResult SignIn(){string claimValue=getCliamValue();} }}
So I get red line under 'getClaimValue()' says 'The name does not exist in the current context.'
So how can I make it work?
Thank.
You're confusing master pages with base classes. A page does not inherit from a master page. A master page provides templated presentation and layout, but does not usually have public methods. You may want to create a base class for your controller and put your method there.
When I'm developing in NetBeans I have a lot of confusion due to the amount of tabs open. In most cases the controller has the same name of the view or model.
In the convention style guide they say that you can prefix a controller file name with a custom suffix, but doesn't work.
My question is, there is any chance to end all the controller files with "_controller"?
In my example the class is class Verify_login extends CI_Controller { and the file is named verify_login.php. Tried with controller.verify_login.php like they say in the guideline but as I say, doesn't work. Lots of confusion in codeigniter's documentation.
Since the controller is the only thing exposed in the URL, I usually name my views and models with an indicator like "user_view" or "user_model". The controller would just be "user" and in this way I always know which file I'm working on.
Am having problems understanding where classes should be kept in CI. I am building an application that describes / markets mobile phones.
I would like for all of my functions (i.e. getphone, getdetails etc.) to reside in one class called Mobile - I understand that this file should be called Mobile.php and reside in the controllers folder.
Can I then have multiple functions inside Mobile.php? E.g.
public function getphone() {
xxx
xx
xx
}
public function getdetails() {
xxx
xx
xx
}
Or do I need to put each function in its own class?
I'd really appreciate looking at some sample code that works. I've been going through the documentation and google for a few hours, and tried all sorts of variations in the URL to find a test class, but without much luck! I've even messed around with the routes and .htaccess...
All I am trying to achieve is the following:
http:///model/HTC-Desire/ to be re-routed to a function that accepts HTC-Desire as a parameter (as I need it for a DB lookup). The default controller works fine, but can't get anything to work thereafter.
Any ideas?
Thanks
Actually it works like this:
Controllers and Models go to their perspective folders as you know it
If you want to create functions that are not methods of an object, you must create a helper file. More info here :
http://codeigniter.com/user_guide/general/helpers.html
Now if you want to create your own datatypes (classes that don't extend Models and Controllers), you add them to the library folder. So if let's say you want to create a class "Car" you create this file:
class Car{
function __construct(){}
}
and save it in the libraries folder as car.php
To create an instance of the Car class you must do the following:
$this->load->library('car');
$my_car = new Car();
More information on libraries here:
http://codeigniter.com/user_guide/general/creating_libraries.html
Yes, you can have as many functions in a controller class as you'd like. They are accessible via the url /class/function.
You can catch parameters in the class functions, though it's not advisable.
class Mobile extends CI_Controller{
public function getPhone($phoneModel=''){
echo $phoneModel;
//echo $this->input->post('phoneModel');
}
}
http://site.com/mobile/getPhone/HTC-Rad theoretically would echo out "HTC-Rad". HOWEVER, special characters are not welcome in URL's in CI by default, so in this example you may be met with a 'Disallowed URI characters" error instead. You'd be better off passing the phone model (or any other parameters) via $_POST to the controller.
Classes can exist both as Controllers and Models, as CodeIgniter implements the MVC pattern. I recommend reading more about that to understand how your classes/functions/etc. can best be organized.
Off the top of my head, Pyro CMS is an application built with CodeIgniter and the source code is freely available. I'm sure there are others.
I think it's best you handle it from one perspective, that is; create a utility class with all your functions in it.
The answer to the question of where to put/place the class file is the "libraries" folder.
This is clearly stated in the documentation. Place your class in the libraries folder.
When we use the term “Libraries” we are normally referring to the
classes that are located in the libraries directory and described in
the Class Reference of this user guide.
You can read more on creating and using libraries Creating Libraries — CodeIgniter 3.1.10 documentation
After placing the newly created class in the libraries folder, to use just simply load the library within your controller as shown below:
$this->load->library('yourphpclassname');
If you wish to receive several arguments within you constructor you have to modify it to receive an argument which would be an array and you loading/initialization would then be slightly different as shown below:
$params = array('type' => 'large', 'color' => 'red');
$this->load->library('yourphpclassname', $params);
Then, to access any of the functions within the class simply do that as shown below:
$this->yourphpclassname->some_method();
I hope this answers your question if you have further question do leave a comment and I would do well to respond to them.