I have a site where the directories are set up like this
public_html/framework/cake
public_html/framework/app
public_html/index.php
public_html/contact.php
public_html/aboutus.php
Is there any way to get variables or model data from public_html/framework/app when a user navigates to public_html/aboutus.php?
I would recommend reading the HttpSocket documentation.
An example implementation would look similar to:
/**
* import HttpSocket class
*/
App::import('Core', 'HttpSocket');
/**
* instantiate and make a POST request to http://localhost/contact.php
* sending var1 => test
*/
$HttpSocket = new HttpSocket();
$HttpSocket->post('http://localhost/contact.php', array(
array('var1' => 'test')
));
/**
* response
*/
$response = $HttpSocket->response;
Related
Hello Guys nowadays am working on laravel project and in this project i have make 2 api one is working perfectly like i am getting all the data from database accurately but in the second api i am getting blank data means nothing both api is same but just from one api am getting data from ID and in second api i am getting data from email please help me.
it is my api.php code
<?php
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
// routes/api.php
// POST /api/post?api_token=UNIQUE_TOKEN
Route::post('post', 'Api\PostController#store')->middleware('auth:api');
Route::get('/getemail/"{email}"','EmailController#databyemail');
and it's my EmailController Code
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\email;
class EmailController extends Controller
{
public function databyemail($email){
$data = new email();
$data = email::find($email);
return response()->json($data);
}}
and finally it is my email model code
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class email extends Model
{
protected $table = 'users';
protected $fillable = ['surname','first_name','last_name','username','email','password','language','contact_no','address','remember_token','business_id','status'];
}
please help me why i am getting nothing from database
Thanks in Advance
I think you should fix your Route, you don't need to use " " marks for the variables.
Route::get('/getemail/{email}','EmailController#databyemail');
Just use like this.
Also, find works with Primary key so,
Instead of:
$data = email::find($email);
Use:
$data = email::where('email', $email)->first();
I have the following code that sends my email:
/**
* #param array $to
* #param string $subject
* #param array $vars
* #param string $template
* #param array $from
*/
public function sendEmail(array $to, $subject, array $vars, $template = 'default', array $from = ['dev#example.com' => 'Online'])
{
$transport = 'default';
if (Configure::read('debug')) {
$transport = 'dev';
}
$mailer = new Email($transport);
if ($this->isCommandLineInterface()) {
$mailer->setDomain('http://local.peepznew.com');
}
$this->addRecipients($mailer, $to);
$mailer->setFrom($from);
$mailer->setSubject($subject);
$mailer->setTemplate($template);
if (isset($vars['preheaderText']) === false) {
$vars['preheaderText'] = '';
}
$vars['subject'] = $subject;
$mailer->setViewVars($vars);
$mailer->setEmailFormat('both');
$mailer->send();
}
This code is called from the web interface as well as from the command line. After struggling to get the full url to display in messages sent from the command line, I read the docs and came across this:
Which is why I'm doing the setDomain call. I run my code again, and it still doesn't have full Urls. So I created the exact same function in both the web interface and cli, that looks like this:
$this->sendEmail(
['my.email#example.com'],
'Test Email',
[
'title' => 'We need to select another peep',
'showFooterLinks' => true,
]
);
die;
The default template looks like so (it literally only has this one line in it):
echo $this->Html->link('test link', ['controller' => 'jobs', 'action' => 'select_staff', 1, '_full' => true]);
The emails from the web interface, using the code above, sends perfect. Full URLs and everything. However from the cli, it just sends /jobs/select_staff/1.
Why is this and how do I fix it?
Read the docs closely, they say that the domain set via setDomain() is being used when generating message IDs, ie it's being used in an E-Mail header.
Generating links is something completely different, and is affected by the App.fullBaseUrl configuration option, which is by default derived from env('HTTP_HOST') in your applications config/bootstrap.php, unless already configured in config/app.php.
It's also possible to configure the base URL separately for the CLI environment in your config/bootstrap_cli.php file, there should already be a commented snippet for doing so that looks like this:
// Set the fullBaseUrl to allow URLs to be generated in shell tasks.
// This is useful when sending email from shells.
//Configure::write('App.fullBaseUrl', php_uname('n'));
See also
Cookbook > Console Tools, Shells & Tasks > Routing in the Console Environment
Source > cakephp/app > config/bootstrap.php
Source > cakephp/app > config/bootstrap_cli.php
Source > cakephp/app > config/app.php
i am using laravel in windows OS, with MySql as the database, and am trying to connect my web application's login to laravel default login/registration. the default query that runs in laravel on login is select * from users where email="something" i want to know where this query is located in order to modify it according to my preferred table format. any help would be appreciated. thanks
This is located in the AuthenticatesUsers trait via the attemptLogin method:
/**
* Attempt to log the user into the application.
*
* #param \Illuminate\Http\Request $request
* #return bool
*/
protected function attemptLogin(Request $request)
{
return $this->guard()->attempt(
$this->credentials($request), $request->filled('remember')
);
}
The actual implementation is done with guards via the attempt method:
public function attempt(array $credentials = [], $remember = false)
See the Illuminate\Auth\SessionGuard for an example:
https://github.com/laravel/framework/blob/5.5/src/Illuminate/Auth/SessionGuard.php#L347
I have a web application written in CakePHP that needs to read request data from a JSON payload as opposed to standard application/x-www-form-urlencoded data. I would like to be able to access this data via the standard $this->request->data methodology. Is there a supported way to extend the CakeRequest object so that it is able to accept requests in this format?
Here's how you can customize the CakeRequest object's functionality:
Insert the following into app/Config/bootstrap.php:
/**
* Enable customization of the request object. Ideas include:
* * Accepting data in formats other than x-www-form-urlencoded.
*/
require APP . 'Lib' . DS . 'Network' . DS . 'AppCakeRequest.php';
Create app/Lib/Network, and add AppCakeRequest.php:
<?php
/**
* AppCakeRequest
*
* Allows for custom handling of requests made to the application.
*/
class AppCakeRequest extends CakeRequest {
// Do your magic, and be careful...
}
Edit app/webroot/index.php:
$Dispatcher->dispatch(new AppCakeRequest(), new CakeResponse(array('charset' => Configure::read('App.encoding'))));
Be careful, make sure you know what you're doing, and good luck.
HI! I'm trying to create the web service in the cakePhp. I'm new to cakePhp and only recently start working on it. I found a useful tutorial at http://www.littlehart.net/atthekeyboard/2007/03/13/how-easy-are-web-services-in-cakephp-12-really-easy/
I created both the controller and index.ctp files as described in the tutorial. But when I typed the url (http://localhost:81/cakephp/foo) of the controller to run the file, I got the following error:
// controllers/recipes_controller.php
/**
* Test controller for built-in web services in Cake 1.2.x.x
*
* #author Chris Hartjes
*
*/
class FooController extends AppController {
var $components = array('RequestHandler');
var $uses = '';
var $helpers = array('Text', 'Xml');
function index() {
$message = 'Testing';
$this->set('message', $message);
$this->RequestHandler->respondAs('xml');
$this->viewPath .= '/xml';
$this->layoutPath = 'xml';
}
}
CakePHP: the rapid development php framework
Missing Controller
Error: FooController could not be found.
Error: Create the class FooController below in file: app\controllers\foo_controller.php
Strange thing is that (everyone can see) that controller text is loaded in the error page, but error shows that controller file is not found.
I also tried to follow the tutorial on book.cakephp.org/view/477/The-Simple-Setup.
But same error also occured here. Anyone can help? By the way I also changed the text of routes.php to work it with web webservices.
Thanks
The fact that the contents of your FooController file is being output in the browser indicates that the PHP is not being executed.
You need to ensure that the definition for your FooController class is enclosed in <?php and ?> tags, like this:
// controllers/recipes_controller.php
/**
* Test controller for built-in web services in Cake 1.2.x.x
*
* #author Chris Hartjes
*
*/
<?php
class FooController extends AppController {
var $components = array('RequestHandler');
var $uses = '';
var $helpers = array('Text', 'Xml');
function index() {
$message = 'Testing';
$this->set('message', $message);
$this->RequestHandler->respondAs('xml');
$this->viewPath .= '/xml';
$this->layoutPath = 'xml';
}
}
?>
You have entered the URL http://localhost:81/cakephp/foo. Cake correctly interprets this to mean you are looking for the index action on the FooController. The error doesn't mean it has found the file, just that it has worked out what to look for but hasn't found it where it expects it to be.
The line: Error: Create the class FooController below in file: app\controllers\foo_controller.php tells you what should be there (and what, as a minimum, it should look like). Check that you have named the file correctly and that it located where the error says it should be.