CakepPHP: help with the cakephp comments plugin - php

Hi I'm trying to use the CakePHP comments plugin found here http://cakedc.com/downloads/view/cakephp_comments_plugin but the instructions are really hard to follow. I've managed to add comments but it's displaying the commentWidget that's not working.
I'm getting confused at this part i think
To work properly, the component needs
a specific variable to be set in every
action using it. Its name should be
either
Inflector::variable(Controller::$modelClass)
or Comments::$viewVariable should be
set to other name of this view
variable. That variable should contain
single model record. for example you
need to have next line in you view
So far I've created the comments table, added it to the pluging and components arrays and added the following code to the controller:
public function beforeFilter() {
parent::beforeFilter();
$this->passedArgs['comment_view_type'] = 'flat';
}
I added the route
Router::connectNamed(array('comment', 'comment_view', 'comment_action));
And also the Comments.CommentWidget as a helper in my controller.
I'm just wondering if anyone has used this plugin before and can help me out?
thanks,
Jonesy

You're right - the documentation is really confusingly worded. However, if I understand correctly, what it wants is a copy of the record of the piece of data the comment will be attached to passed to the view the comments will render on.
So say you're making an event page, and you want people to comment on the event. You need to send to the view a variable called "event" with a copy of the base data for that event.
From their example they show: $this->set('post', $this->Post->read(null, $id));
For your event, you'd do something like $this->set('event', $this->Event->read(null, $id_of_event));
The Comment view probably needs this data for hidden fields so it can populate it with the model name and the event id.

Related

PHP - Load variable page content

Apologies again, as I'm new to PHP so not fully sure how this works, but thought I'd ask.
I have a page called contract.php, which I'm hoping to use as a template so that when someone selects the contract they wish to view it goes to the contract.php and loads the content for that particular contract.
Hopefully I shouldn't need to create a page for every single contract, I was hoping that I could use the contract ID, so that when the navigate to the page it would show something like contracts.php?contractid=555 and then loads the contracts details for contractid 555, so this does this for each new contract that's listed.
The issue I'm having is, I'm not sure how best to go about it, or how to use this ?contractid='xxx' etc.
Any help would be appreciated.
Many thanks
$_GET manual.
after reading the contract id from the get variable, you can search your DB for that contract and echo the specific data of this contract.
Also consider using $_POST so that you can't easily see any contract by changing the url by yourself
You can fetch respective data from your database for each contract using the contract ID. Inside the contracts.php, check whether contractid variable is set and not empty, using isset($_GET['contractid']) && !empty($_GET['contractid']). If it is true, then fetch respective data from the DB and display it to the user, in the template that you must have created.
Hope this helps. If you need more help then paste your code here.

Trying to add a second view in a new component in Joomla! 3.x

I'm developing a component for Joomla! 3.x and I came across a strange issue. I followed the official documentation (http://docs.joomla.org/J3.2:Developing_a_MVC_Component/Adding_backend_actions) and I was able to get somewhere. Now the problem is that I wanted to expand the tutorial and create submenus within the components menu in the backend. I succeeded with this too.
The 2 submenu selections link correctly to 2 different views and I am able to fetch data from different tables nicely. The problem is that I cant add new entry to the database using my second view. The first view works fine. On the second view, when I click the green Add button, I get a jquery error: Uncaught TypeError: Cannot read property 'task' of null
The problem is that the addNew method cant find municipality.add or something. However this (almost) same code works for the default view.
What I'm trying to do is to display the data of 2 different tables in the DB and then being able to edit delete or add new.
Any ideas? Thanks in advance
The code
municipality.add
and
municipalitys.delete
refers to two different controllers, named municipality.php and municipalitys.php
You need to ensure the methods are present, in your case municipality.php should contain a
public function add()
which is not there. For a reference on how to implement it look at the other controller (most likely you'll invoke the add() method of the relevant model).
Or possibly you're extending the municipality controller from a different ancestor that doesn't implement the add method
Answering my own question, the problem was in the views/municipalitys/tmpl/default.php.
The form contained in that file was wrong, missing the id="adminForm" and the proper action= value.

how to use a controller's action in all controllers

I have an action that renders search view to do search as the above search bar in this website, so its should be shown in every view.
I don't know what is the mechanism to do it. for example if I make the search action as a widget this will not be fine, because the results of search will be shown in the same position of the search widget ( at the top of website).
so, how I can make a search action that should be shown in every view in the website?
In order to resue same search function in everywhere, you need to create a widget.
I have explained briefly in How a widget works, then you can attach it in every view that you want.
If you don't have any idea to begin, check this out: Yii ESearch
Here are some references that would be useful:
how-to-use-a-widget-as-an-action-provider
actions-code-reuse-with-caction/
Yii Widget
If you want to add something to every view then you should add it to the layout. By the sounds of it you don't need to use a widget at all, although it would probably help with code maintainability.
You never mentioned a requirement for ajax so keep it simple and don't use it. When someone enters a search and clicks submit (or presses return) then the form submits to the SearchController. This way there is no need to have a search action in each controller.
If you particularly want the same action in every controller then create a Controller base class with that function in it and inherit from it to create all your other controllers.

Pass GET to other view Joomla

I'm developing a component (backend). I got a listview with a $_GET that contains a ID number
and i want to send the $_GET to the add view
(JToolBarHelper::addNew('item.add', 'JTOOLBAR_NEW');)
But i don't find any good solution on this, i have inserted the value in listviews form, but i am not possible to take it out. I tried to create a add function in the controller for my add/edit view but is dosen't work. Hope someone can help me out.
You might consider JApplication/JSession like this

Adding extra field on opencart checkout

I'm using opencart v.1.5.1 How do I add extra text area on opencart checkout page?
I've added Step 6 using photoshop, how do I code that on opencart?
I don't know about your programming background, but you need to be a little bit more than familiar with PHP, AJAX, JavaScript and of course MySQL, you should also know about the MVC architecture. If you think you have enough knowledge of those then here is what you need to do:
Create a controller class and name it lets say "remarks"
class ControllerCheckoutRemarks extends Controller {
public function index() {
// Your code
}
}
add the code you need to process the data, you can get some ideas by looking at "checkout/guest/shipping" controller class. What you need is quite similar to what that class does.
if you need to interact with the database in order to process the data then you need to create a Model class in the same route under the Model folder and write your functions in it. again you can get the idea from other model classes. But I don't think you need this, probably you want to add this information to your order, in order to do that you should modify the Order class, both Controller and the Model !
Finally you need to create a template file for it, once again open the template file for "checkout/guest/shipping" and see how they did it, then you create your own.
For the controller and model classes make sure you name them properly.
There is one more thing you need to do, The controller class for the step 5 sets the redirect to the next step which by default is the Confirmation. Change this line and make it redirect to your section and do the same thing for the new section and redirect it to Confirm:
url: 'index.php?route=checkout/shipping'
I can only guide you what to do, how to do it is your job :D If you are a programmer then I don't think you'll have any problem with it. if you're not i guess you'll need someone to do it for you :)

Categories