I am new in joomla. I am working joomla component which was developed by other coder. I can edit page view, data etc which is displaying on page. But I am unable to find from where I can edit data which is coming from default. There is controller table in component, but if I remove controller folder still its loads.
In my one of view file I put this
print_r($this);
die("");
It prints all the data which is related to this component. I want to find code from where this data is coming so i can edit that data as per requirement. Its all only one view file, because controller folder in this component is removed.
This is somewhere in joomla main files.
Thanks
it's a bit hard without seing any code, but assuming the original author followed joomla standards, the data comes from the model having the same name as the view.
e.g for com_xyz/views/viewa/view.html.php, the model would be com_xyz/models/viewa.php
Related
I am new to Joomla component developement and currently fighting with certain basic design patterns!
Lets say, I am developing a component where users can enter simple notes into their personal notebooks.
On calling the view "index.php?option=com_notebook&view=notes" I simply show a list of all note entries of the user. No problem so far, this is working fine.
Now I want to extend my component with the following feature: on opening the view "index.php?option=com_notebook&view=notes", I want to check if the user has already created a notebook before. If yes, I show all note entries, if not, I want to load a different view which contains a form to create a new notebook with certain options.
But how can this be done in a clean way?
For sure, I just can implement the form within the view "notes", but this is not the clean way, isnt it?
I also tried to override the function "display()" of the main controller and set the view manually if no notebook exists. But if I do so, I have to handle all calls to other views of my component manually within the function "display()". To solve this, I created a copy the original implementation from the class "JControllerLegacy" and changed it to my needs - this is working - but is this really the best way to handle problems like this?
So I ask you, what is the best approach to solve this problem?
Thx a lot!
According to me the best solution of your problem is to provide "New" and "Edit" button to your notebook listing page and create edit view of notbook. Same as Joomla has articles and article views.
So, As you mentioned above if use dose not have any notebook then he/she can create a new notebook using that "New" button. when user clicked on "New" button he has blank form where he/she can create new notebook.
here is the example how to create listing and edit view in Joomla. Hope this will help you.
https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Adding_backend_actions
I converted a site from 1.7 to 2.5, and all is really just about done, but I'm having one issue. I want to use these two custom K2 templates that existed in the previous version for both user registration and user profile because they were using K2 as the user registration mechanism.
I've configured K2 to Enable K2 User Profile:
but for whatever reason, when I navigate to index.php?option=com_users&view=register it's still grabbing the default registration form. Now, I thought it was maybe the URL, but the old 1.7 system is using the same URL. So, with some debugging I found that when the layout is told to search for a file, the K2 path isn't in the array.
What did I do wrong here?
NOTE: I also tried configuring the User Manager so that Allow User Registration was set to No, but I just get a 403 then because it's just not overriding with that K2 template.
UPDATE
As I stated in the comments, for whatever reason I don't have a K2 registration menu item type. However, the weirdest part is that the 1.7 version didn't point to the K2 registration either.
A little more background. This is a really hacked together system. The menu is actually built with a Jumi module that is straight forward custom and when the user is logged in the link that is used for the profile for example is this:
index.php?option=com_users&view=user&layout=form&id=3
and the register link, which is also custom (i.e. it's a link on a custom view) is this:
index.php?option=com_user&view=register
So, in short, I don't know enough about the Joomla navigation system to understand how to get those links to reroute to the K2 views that reside /components/com_k2/templates folder.
UPDATE
I put the register.php view that existed in /components/com_k2/templates folder into the /templates/tmplname/html/com_users/register folder and renamed it default.php so that the default user registration navigation would choose that view. And it did choose that view, no real surprise, but it also failed on a line like this:
<?php if(count(array_filter($this->K2Plugins))): ?>
because K2Plugins is null and that's not allowed for the array_filter function. I'm guessing this is because if this view were inside the com_k2 folder, like its original location, this would be available. I'm trying everything I can think of now.
It also threw on this line:
$this->K2Params->get('recaptchaOnRegistration')
because K2Params is null so of course get isn't available.
I found the problem, finally! The /plugins/system/k2/k2.php was catching the onAfterDispatch method for the navigation of com_users. If it was com_users and register or profile then it redirected and leveraged a different view. Well, the problem was that the old code said com_user instead of com_users. Silly!
Maybe I want to add a new view, and also a new Menu Item Type to content component.
What are the steps please?
UPDATE
Question (by #ValentinDespa) :
You want to extend com_content functionality or you want to override a
view or to build a new component that does something?
As I said, I want to extend com_content and add a new view to it. There are some views like Single Article, Category Blog, and Category List right now.
I want to add another menu items called Article Titles, so titles only will be displayed but with some parameters (like columns count).
It is a need that is not supplied by current features.
NOTE
Guys, it doesn't matter what my new view should be like, please tell me How to create a new view.
Yes You can create a new view.
Its simple just copy any of the view (category,blog) from your com_content.
The file structure should be like inside the folder.
Step 1
view.html.php
tmpl
your layout names(default.php)
xml file.
Also remember to change the class name of the view.html.php
Step 2
Add a controller file (just make a copy of existing one category or blog)
Controller name must be your new view folder name.
Also remember to change the class name of the controller
step 3
add a model file for your new view (same make copy of any existing)
remember to change the class name and file name should be view folder name.
Then you can access this view by giving correct url.
eg: www.example.com/index.php?option=com_content&view=yourviewname&layout=yourlayoutnames.
Here I mentioned view folder name must be controller and model file name we can achieve with other name also but it will create problem for you when you are not good in joomla.
Note:
For adding a view you don't need to install a component its not a good idea at all.
Also You can add multiple layouts in a view
inside your tmpl folder just create new files.Also don't miss the controller and model to put in com_contents/controller and com_contents/model folder
for More help take a look at this
You have the URL:
http:///www.site.com/controller/method/values/1/2/3
Do I have to always have the controller being called or can I have the view being called and instantiate the controller inside the view or in a bootstrap file referring to this view?
What I don't get it is if I need more than 1 controller on the view, how to archive that?
For example:
On my index page I want run a simple CMS, where the admin can change the text blocks and images of the site. That would be on the content management controller.
On my index page I also got the latest added products vitrine, what would be controlled by the controller products.
If I define www.site.com/contentmanagement or www.site.com to run the contentmanagement controller, how the product controller would be called?
Also, another example. On my menu I got a link to a page called aboutus, that would be a simple page and the only feature needed would be the content management controller to manage the texts blocks.
If I follow the pattern Im reading all over the place I will end with a link like:
http://www.site.com/contentmanagement/method/aboutus
?
Kinda lost here cause surely this URL will look weird. Would be much easier to have the URL calling the view http://www.site.com/aboutus and a boot file where I can tell the controller that should be loaded when the surfer is there ...
bootstrap would look like:
switch($view)
case: index
controller load contentmanagement
controller load product
case: aboutus
controller load contentmanagement
I appreciate any help or a light here, thanks.
by the way, Im coding in PHP.
Hm, if you want to have text blocks and images of the site (one controller), and products vitrine (second controller), then call the methods you need in one controller..
I would do it this way: when you request index page with all the elements you mentioned above, actually one controller is called, and it decides which view to show.. so in that controller, you call the all methods that you need, get the data, and pass it to the view.. if the methods are called from other controllers, just call that methods and get the data.. i often make some static methods in controllers, which I can call anywhere, so I don't have to instantiate whole object..
E.g. you call www.site.com/contentmanagement, controller is called, which will display index view, and in that controller, you call all methods you need, prepare the data, and pass that data to the final view which will be displayed..
Do I have to always have the controller being called or can I have (..blah blah..)?
It kinda depends on what you understand by "call".
Controller needs an ability to change state of both View and Model(s).
And each View need ability to request data (in Model2 MVC) from Model(s).
Thought Controller should not cause the rendering of View (which is common in all the RoR sycophants) much like View has not business in executing actions on the Controller.
What I don't get it is if I need more than 1 controller on the view, how to archive that?
Views and Controllers should have 1:1 relationship. If your view need more then one controller, you might want to look into HMVC architecture.
For example: On my index page I want run a simple CMS, (.. more blah .. ) how the product controller would be called?
CMS should be a separate application ( or at least module ) with multiple controllers.
If I follow the pattern Im reading all over the place I will end with a link like: http://www.site.com/contentmanagement/method/aboutus ?
Why not just http://site.com/cms/content/2/edit (where 2 is the ID for "about us" page). There is no law which states that URL structure for site administration must mirror the publicly available page .. hell .. it can actually cause increased vulnerability.
I am going to try to walk
What I don't get it is if I need more than 1 controller on the view,
how to archive that?
For example: On my index page I want run a simple CMS, where the admin
can change the text blocks and images of the site. That would be on
the content management controller. On my index page I also got the
latest added products vitrine, what would be controlled by the
controller products. If I define www.site.com/contentmanagement or
www.site.com to run the contentmanagement controller, how the product
controller would be called?
Having the URL to contains the controller's name is definitely nice, but it is not the requirement for MVC. So you don't have to necessary map your controller to the URL itself. A classic MVC does not tie itself to a particular naming convention, so you could call your product controller via different URL which then process the product and show the view for the product.The important for MVC is to have one controller that deals with sets of model and resulting in one view as the presentation layer. In your particular example, your entry point seems to be a single controller that interacts with both ContentManagement and Product Class/Module and the resulting interaction produce a single view.
bootstrap would look like:
switch($view)
case: index
controller load contentmanagement
controller load product
case: aboutus
controller load contentmanagement
Thus your original interaction above is not completely off, except that you are not really calling two controllers, but rather doing the following upon hitting index:
Load a controller, let's call this one IndexController
Load ContentManagement module to get the related content, you might want to put the info as part of your Model for the Index page
Load Product module to get related products, again put this into your Model
Pass the Model containing the info for rendering the page into the View
In your View, you render the Model that contains both Content from ContentManagement module and Product list from the Product module thereby producing a single view
If I follow the pattern Im reading all over the place I will end with
a link like: http://www.site.com/contentmanagement/method/aboutus ?
This is again not a requirement, you should follow what makes sense and easier for the users. Also, if you are required to follow the conventions, you could always make your URL pretty by using URL mapping.
What you are looking for is called HMVC and there are a couple of frameworks for that out there, like Kohana.
Also see this question:
What is the HMVC pattern?
I have created a new plugin named 'adv' in my elgg site.
And in this plugin iam listing the users.Which using the view from other elgg plugin 'profile
ie the page profile/views/default/profile/listing.php.
Now i need to set a link in the existing view of each user.So i have to edit the profile plugin , mainly the page profile/views/default/profile/listing.php
But how can i do this, without modifying elggs default plugin 'profile'.
I have tried a method that i have copied the folder 'profile' from profile/views/default/profile and put it in adv/views/default/.But it donot working.]
Is any solution for adding new link to the user view with editing other plugin, only editing our own plugin example 'adv'.
You'll need to override the profile/listing view, but only when Elgg is rendering your plugin's pages, not to interfere with other plugins that might want to use the core profile/listing view.
My approach to this problem is the following:
Create a new directory that will hold the views that you want to override.
In your case, I'd create the "adv/views/mod" directory within your_site_root/mod.
Add the view you'd like to override into this directory.
Again, your case, copy the profile/views/default/profile/listing.php to the following location: adv/views/mod/default/profile/listing.php
Make your modifications to the newly created view.
You can now safely modify the adv/views/mod/default/profile/listing.php file to your liking
Tell Elgg to use the special view when your plugin is rendering the page. This means you'll have to call the set_view_location(..) method either from your page_handler function, or the php files that are referenced by your page_handler and usually prepare the data for the views (like index.php or read.php, but I don't know your plugin's file hierarchy)
So in your case you'd call set_view_location('profile/listing', $CONFIG->pluginspath . 'adv/views/mod/'); either from your page_handler or from one of the above files.
Make sure that $CONFIG is present and available by referencing it (global $CONFIG).
Please check if "Use view filepath cache (recommended)", is disabled in the site administration. Because elgg uses hard view cache. Or delete the view_cache file from the data directory. And also make user your plugin is below the "Profile" in the plugin list.