Cakephp 2.0 captcha component gives warning - cakephp-2.0

I am using Captcha component with cakephp 2.0. Though Its going well but my traced issue with this component.
Warning: Argument 1 passed to Component::__construct() must be an instance of ComponentCollection, none given, called in ...
When I tried to find solution it gives me two line code in somewhere comment.
_controller = $collection->getController();
parent::__construct($collection, $settings);
function startup( ) {
$this->Controller = $this->_controller;
}
The solution code is something like this which ended me with error.
Captcha component link is http://www.devarticles.in/

I found the solution for Cakephp 2.0. In controller where you are creating instance do it like this..
$myvideo = new MyVideoComponent(new ComponentCollection()); //make instance

Please download working Captcha Component for CakePHP 2.x from author's website

Related

CakePHP 2.5.2 Themeing and theme.ctp

I've created a simple application that is about to be vastly expanded upon and get a bit out of hand if I don't get the theme sorted out early as I need to start working with tinyMCE.
I created my theme in app/View/Themed/Default and added the following into my app controller
public $theme = 'Default';
Something seems to be working because cakePHP is not rendering my views and is giving me the following errors.
Error: The view for {controller name}Controller::add() was not found.
Error: Confirm you have created the file:
/home/cake/public_html/app/View/Themed/Default/{controller}/theme.ctp
I've been reading through the documentation and nowhere in there does it tell me that I need to create a folder for every controller and add a theme.ctp file inside. so I'm at a bit of a loss as to what needs to go into this theme.ctp file.
If I add the Controller folder, and a blank them.ctp file, the view is not rendered. So I am assuming something vital is required here.
I discovered the problem.
Further down the page from legacy code that was ported across, the following code was sitting at the bottom of the page.
AppController.php
function beforeRender() {
$this->view = "Theme";
$this->theme = "default";
}
So it was being forced into rendering a view that did not exist.

Sanitize string to using angularjs

I basically want to use tel tag to make a phone call.
<a class="callButton" href="tel: {{phoneno}}"></a>
I am using $compileProvider to remove unsafe tag which comes by default, It works perfectly fine post 1.0.4v of angularjs. However below this version it doesnt work. Can anyone suggest how to implement this feature using angular version 1.0.4 or below?
Here is the sanitizing code which I am using in js file
app.config(['$compileProvider', function ($compileProvider) {
$compileProvider.urlSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|tel):/);
}
Assume I have already defined app variable.
P.S. This is an enhancement for particular app which basically works below 1.0.4v
Thanks
Add this to your scripts after angular is loaded.
I asume your on 1.1.5, but change to whatever you need the version to be.
http://code.angularjs.org/1.1.5/angular-sanitize.min.js
Example:
sanitizeSomething = function(string) {
return $sanitize(string);
};
sanitizedString = sanitizeSomething(string);

CakePHP: Passing data to plugin

I have installed a plugin (SignMeUp) for the user registration, and according to the documentation the registration function inside my User Controller has to look something like this:
public function register() {
$this->SignMeUp->register();
}
Looking at the $this->data array inside this function shows that everything is working fine. However, when I use
debug($this->data);
inside the registration() function of the plugin (the one I just directed my function to), the array is empty. Somehow the data doesn't get passed on. What could be the cause?
Resolved! This can be solved by replacing all the $this->data occurences in the SignMeUpComponent with $this->controller->request->data
It's a change from Cake 1.3 to Cake 2.x

Custom Button or Link to a Visualforce page with a custom controller

I have a Visualforce page using a custom controller that is used to edit multiple records under an opportunity.
I'd like to create a custom button or link from Opportunities to this Visualforce page.
Currently the link looks like:
/apex/ExamplePage?oppId={!Opportunity.Id}
This works fine in the development sandbox, but when it is deployed as part of a managed package the link breaks as the page reference doesn't have the namespace prefix.
I found the post Managed Package Redirecting Problem on the Force.com Discussion Boards which implied it should be possible to use $Page to reference the Visualforce page in the URL. E.g.
{!URLFOR($Page.MyExamplePage,'',[objectId = campaign.id])}
But doing so only gives me the syntax error:
Error: Field $Page.MyExamplePage does not exist. Check spelling.
There is another part to the post that suggests using an Apex class and Execute Javascript to work around it. But it appears to me that this has just moved the namespace issue into the Javascript.
How can I safely reference the Visualforce page to work both inside and outside a managed package?
Best to do this from an Apex PageReference return value. Something like this will work:
public PageReference returnPage()
{
return Page.MyExamplePage;
}
Then call this from Visualforce:
<apex:commandButton value="Go To New Page" action="{!returnPage}"/>
The Apex Page call will handle the translation for you.
[EDIT]
Create a bare bones Visualforce page like this:
<apex:page standardController="Opportunity" extensions="TheController" action="{!returnPage}"/>
Add the above returnPage() method to a new TheController (or whatever) class. It doesn't even need a constructor. The class can look like this:
public TheController
{
public PageReference returnPage()
{
return Page.MyExamplePage;
}
}
Then from the Opportunity settings page go to Buttons and Links and create a new custom Visualforce button selecting the new page you just created.
That should do it.
It occurred to me that one less than ideal option would be to create two custom buttons in each case. One with the managed package namespace and one without.
When building the package the correct custom button could be selected.
One issue with this approach is the need to maintain two custom buttons.
It seems the answer is simply /apex/package__Page as provided here by #zachelrath. I can confirm this works in managed packages in production orgs as well as in development.
The post on the developer boards that you've linked to shows the following javascript being used for the button:
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
var pageUrl = sforce.apex.execute("mynamespace.PageUrl", "getPageUrl", {objectId:"{!Campaign.Id}"});
window.location.href = pageUrl;
i.e. they're using javascript to call a webservice method in the class they've defined in order to get the page reference. Doing this would allow you to get the URL of the page in apex, where the managed package won't play an impacting part.
That said, the first parameter is the fully-qualified class name, so you could probably check the return value for an error (I don't know the error return value, so I'm assuming it's null here):
// try the namespace first
var pageUrl = sforce.apex.execute("mynamespace.myClass", "getPageUrl", {objectId:"{!Campaign.Id}"});
if (pageUrl == null)
{
pageUrl = sforce.apex.execute("myClass", "getPageUrl", {objectId:"{!Campaign.Id}"});
}
window.location.href = pageUrl;
Obviously you need to check what happens when sforce.apex.execute() fails, and you'll likely want some more error handling.

CakePHP - Render a view that is actually plugin's view from Component

Morning guys,
So this is my first time developing a plugin for CakePHP. Here's what I am doing in startUp of the component.
//component
function startUp(&$controller){
//....
if($render){
$controller->render("return", "ajax");
}
}
By default render will look at app/views/<controllers>/return.ctp and app/views/layouts/ajax for this render call.
Is there anyway that I can give a directive to render from app/my_plugin/views/awesome_stuffs/return.ctp and app/my_plugin/views/layout/ajax.ctp instead?
I believe the third param of Controller::render($file, $layout, $file) could do the job, but is there any better Cake way of doing things?
Plus, is that considered a good practice to take over controller's rendering function like that?
One way is to call the PLUGIN controller/action URL in your AJAX call, instead of the main app controller/action URL.
ex:
instead of:
http://domain.com/controller/action
you call:
http://domain.com/my_plugin/controller/action
When you do it this way, the plugin views & layouts are called automagically. See:
http://book.cakephp.org/view/1118/Plugin-Tips
http://book.cakephp.org/view/1115/Plugin-Views
Otherwise, the only way I know of is manually setting paths as you mentioned or controller-wide via:
var $viewPath = 'path/to/plugin/views/';
var $layoutPath = 'path/to/plugin/layouts/';
You might want to try setting $this->view to the plugin dotted view file you want to render.
add to your source
$controller->plugin = "pluginname";

Resources