Unable to change the echo output - phalcon

I have used PhalconPHP devtools to create a project skeleton and did some testing in the indexAction(){} from the indexController.
My index controller:
class IndexController extends ControllerBase
{
public function indexAction()
{
echo "OUUUUUTPUUUUUUUUUUUUUUUT";
}
}
and index.volt looks like:
<!DOCTYPE html>
<html>
<head>
<title>Phalcon PHP Framework</title>
</head>
<body>
<?php echo $this->view->getContent(); ?>
{{ content() }}
</body>
</html>
I know this way I am getting double the content. But this is for debugging.
The output I get is:
<h1>Congratulations!</h1>
<p>You are now flying with Phalcon. Great things are about to happen!</p>
<h1>Congratulations!</h1>
<p>You are now flying with Phalcon. Great things are about to happen!</p>
I am using Chrome browser for testing, and Ubuntu server 12.04 for PhalconPHP 1.3.0.

Phalcon view uses output buffering, I'm sure that's the reason why you're not seeing the echo output, since the view has control over that. You can disable the view to print stuff directly from the controller:
public function indexAction()
{
$this->view->disable();
echo "HELLO";
}
To address the actual debugging question, I suggest to stick with Xdebug – it works perfectly fine with Phalcon and supported by most IDEs, like PhpStorm or NetBeans, and has browser extensions (Chrome, Safari, etc.) It takes awhile to get the head around the first time, but the time invested is totally worth it. Highly recommend.

I guess, this is what need:
public function testAction(){
echo 'Hello world';
$this->view->setRenderLevel(View::LEVEL_NO_RENDER); //will stop render view
}
I use it to output JSON directly from controller. :)

$this->view->setContent('OUUUUUTPUUUUUUUUUUUUUUUT');
or
echo 'OUUUUUTPUUUUUUUUUUUUUUUT';die();

Related

Microsoft WebHelpers with NETCore.App (2.1)

I'm trying to get the below code to work, but I keep getting compatibility problems with Microsoft.Web.Helpers v 3.2.6 and my current SDK package of NETCore 2.1. Also, for the life of me, I can't get the simplest calls of IsPost and Request to be recognized. I'm sure it's an obvious fix, but I can't find it!
Thanks in Advance for any direction...
#using Microsoft.Web.Helpers;
#{
var fileName = "";
if (IsPost) {
var fileSavePath = "";
var uploadedFile = Request.Files[0];
fileName = Path.GetFileName(uploadedFile.FileName);
fileSavePath = Server.MapPath("~/App_Data/UploadedFiles/" +
fileName);
uploadedFile.SaveAs(fileSavePath);
}
}
<!DOCTYPE html>
<html>
<head>
<title>FileUpload - Single-File Example</title>
</head>
<body>
<h1>FileUpload - Single-File Example</h1>
#FileUpload.GetHtml(
initialNumberOfFiles:1,
allowMoreFilesToBeAdded:false,
includeFormTag:true,
uploadText:"Upload")
#if (IsPost) {
<span>File uploaded!</span><br/>
}
</body>
</html>
The WebHelpers library is not compatible with ASP.NET Core. It relies on System.Web, which .NET Core has been designed to move away from.
The replacement for the IsPost block is a handler method. By convention, a handler method named OnPost will be executed if the method used to request the page is POST (which is what the IsPost property used to check).
Personally, I never understood the point of the FileUpload helper unless you wanted to allow the user to add additional file uploads to the page (which you clearly don't in this case). An input type="file" is easier to add to a page.
File uploading in ASP.NET Core is completely different to Web Pages. Here's some guidance on it: https://www.learnrazorpages.com/razor-pages/forms/file-upload

Unable to use "Letters" from "CKeditor"

I'm trying to use Letters as the main collaborative text editor for one of our projects. But, I'm unable to run even a simple demo.
This is my "index.html" test page:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="letters.js"></script>
<meta charset="UTF-8">
<script type="text/javascript">
function load() {
Letters.create( document.body, {
cloudServices: {
tokenUrl: '<Development token URL from https://dashboard.ckeditor.com>',
uploadUrl: '<Upload URL from https://dashboard.ckeditor.com>',
documentId: 'cats'
},
title: 'Cats',
body: `<p>Cats are awesome.</p>`
} )
.then( letters => {
console.log( letters.getTitle() );
console.log( letters.getBody() );
});
}
</script>
</head>
<body onload="load()">
</body>
</html>
There's also a "letters.js" file, but I couldn't even find a download link for Letters. I had to look at the demo page source to find it. If anyone knows an official link, please tell me.
When I open this file (locally or within a web server), nothing happens. The console shows this messages:
Logging on browser console. See `cloudServices._logUrl` configuration. Object { message: "letters-restarteditor: Restart.", level: "error", stackTrace: "value#file:///home/(...)/letters.js:1:1018463\n", data: {...} } letters.js:1:47910
Logging on browser console. See `cloudServices._logUrl` configuration. Object { message: "letters-restarteditor: Restart.", level: "error", stackTrace: "value#file:///home/(...)/letters.js:1:1018463\n", data: {...} } letters.js:1:47910
Logging on browser console. See `cloudServices._logUrl` configuration. Object { message: "letters-restarteditor: Switched to offline mode. Too many restarts.", level: "error", stackTrace: "value#file:///home/(...)/letters.js:1:1018463\n", data: {...} } letters.js:1:47910
Does anyone knows what can be happening? Is "Letters" a stable and reliable tool to use in a big project? Being built over CKEditor5, is CKEditor5 a stable and reliable tool? Or I should better stick with CKEditor4?
Thanks in advance!
There has been no official release of Letters so far, that's why tere is no download link for it. The documentation was published for people who are trying Letters in a private beta program.
I have a good news though, next week there will be a free trial officially available with valid download links, updated documentation, which should work just fine. Within the next few days after offering the trial we will also document on how to customize Letters, add/remove plugins and so on.
As of the end of April 2018, you can sign up to Letters and try it out. For the quick start guide check https://docs.ckeditor.com/letters/latest/guides/integration/quick-start.html

Lithium/Apache on Mac : can't access to the view

I have installed Lithium and tested on Mac.
I can't access to the views that i defined. I can only access to the index file.
My simple project is firstLithium. I set it in /Library/Webserver/Documents
In this project, i create 1 view named posts. Here after is the content of my MVC.
models/Posts.php :
<?php
namespace app\models;
class Posts extends \lithium\data\Model {
}
?>
views/posts/index.html.php :
Lithium is less dense than ium.
controllers/PostsController.php
<?php
namespace app\controllers;
class PostsController extends \lithium\action\Controller {
public function index() {
return array('foo' => 'bar', 'title' => 'Posts');
}
public function add() {
}
}
?>
From web browser :
localhost/firstLithium : it works well
localhost/firstLithium/posts : it doesn't work
Not Found
The requested URL /firstLithium/posts was not found on this server.
The same example can run on ubuntu, but not on Mac. Can i help you to run it on Mac. Thank you in advance.
Definitely looks like a problem with your web server settings, and not Lithium.
Try this guide and if the problem persist, feel free to ping me in #li3 IRC channel.
Also, make sure you have mod_rewrite enabled, for Apache. I'm not sure what the command is, for a Mac, but on Linux, it's:
sudo a2enmod rewrite

Using Yii's Ajax Validation without autoload Jquery

I want to use CActiveForm's AjaxValidation.
My layout view file was like this before enabling AjaxValidation:
<html lang="tr-TR" dir="ltr">
<head>
<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery.js"></script>
</head>
As you see i'm calling jquery framework on my layout page (because i'm using on every page).
And i decided to use CActiveForm's ajax validation. Firstly enable enableAjaxValidation while calling it:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'otel-form',
'enableAjaxValidation'=>true,
)); ?>
And then uncomment this on my controller
$this->performAjaxValidation($model);
But i got $(...).yiiactiveform is not a function error. When i check source code of page :
As you see, one more jquery library included, too. So there are 2 jquery files on page. Because of this i'm getting error. Next i put something like this for disabling jquery.
Yii::app()->clientscript->scriptMap['jquery.js'] = false;
Now jquery is loading only once. But this result is :
<html lang="tr-TR" dir="ltr">
<head>
<script type="text/javascript" src="/istanbulcityhotels/assets/cb2686c8/jquery.yiiactiveform.js"></script>
<script src="/istanbulcityhotels/js/jquery.js"></script>
</head>
jquery.yiiactiveform.js calling BEFORE jquery.js . It should called AFTER jquery.js.
It confused a bit. What should i do?
ADDITIONAL
Yes, i read this question because titles' are really similar, but question isnot same.
Thank you.
You should not be including jQuery manually from your layout. Instead of doing this, include it from within your Controller base class:
public function init() {
Yii::app()->clientScript->registerCoreScript('jquery');
}
Don't forget to call parent::init() from within your concrete controllers.
It seems CActiveForm inserts the scripts before the title tag using CClientScript::POS_HEAD constant. So a workaround is to add this code
<?php
$cs=Yii::app()->clientScript;
$cs->scriptMap=array(
'jquery.js'=>false
);?>
to the top of the main layout file in order stop it from loading jquery, then put the title tag after you load your jquery file
<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery.js"></script>
This way jquery.yiiactiveform.js will be loaded right after jquery.
just put your own jquery on tag title,
just like this:
<script src="/istanbulcityhotels/js/jquery.js"></script>
<title>your title</title>

How to control where YII flashes are placed?

With YII Flashes you can do this:
Yii::app()->user->setFlash('success', "Data saved!");
However, when the flash appears on the page, it appears like so:
<div id="yw1">
<div class="alert in alert-block fade alert-info"><a class="close" data-dismiss="alert">×</a>
MESSAGE
</div>
</div>
How do I control WHERE this is placed? I don't see anything in layouts/main.php that controls this, yet they display?
They won't display anywhere unless you are calling them, a good example in the Yii default app is the site/contact view:
<?php if(Yii::app()->user->hasFlash('contact')): ?>
<div class="flash-success">
<?php echo Yii::app()->user->getFlash('contact'); ?>
</div>
<?php else: ?>
...
And the flash is set using the setFlash method
Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
A possibility is that there may be a check in the Controller root class (protected/components/Controller.php), where someone may have written an init() function that checks for them. This would be called on every controller/action call so it may be there.
Another possibility is that whoever created the project edited the flash method in the framework folder (or possibly extended it), you could have a look there, it is in framework/web/auth/CWebUser.php
But as Mik said, try doing a text search in your project for getFlash or even just flash
I would do a textsearch on user->getFlashes() in your views folder. You can output the messages at any place with this
<?php
foreach(Yii::app()->user->getFlashes() as $key => $message) {
echo '<div class="flash-' . $key . '">' . $message . "</div>\n";
}
?>
You, the developer, need to display flash-messages. Yii does not do that for you.
You display them in a view, as shown by Eskimo and Mik, at a location of your own choosing . Yii could never do that, because Yii does not know the layout of your view.