How to check if a YII app is running from a console or from browser?
I'm new to YII framework and i'd like to know if there's way to know/check if you are running from console or in a browser?
Thanks!
yii
add a comment |
I'm new to YII framework and i'd like to know if there's way to know/check if you are running from console or in a browser?
Thanks!
yii
add a comment |
I'm new to YII framework and i'd like to know if there's way to know/check if you are running from console or in a browser?
Thanks!
yii
I'm new to YII framework and i'd like to know if there's way to know/check if you are running from console or in a browser?
Thanks!
yii
yii
asked Aug 9 '13 at 14:01
zeratool
6711717
6711717
add a comment |
add a comment |
7 Answers
7
active
oldest
votes
Same way you would determine if a PHP application is being run in the console or not.
What is the canonical way to determine commandline vs. http execution of a PHP script?
Thanks, i thought there's a "YII-specific" function that i'm not aware of. Thanks again.
– zeratool
Aug 9 '13 at 14:36
add a comment |
This reply is a bit late but there is a Yii-specific way to do this:
In Yii1 you can do:
if (Yii::app() instanceof CConsoleApplication)
In Yii2 that would be:
if (Yii::$app instanceof YiiconsoleApplication)
Hope that's useful to someone...
add a comment |
You should also be able to do:
echo get_class(Yii::app());
which will tell you what type of app you're in ...
add a comment |
The most efficient way seems to define in the root file index.php this line :
define ('WEBAPP', true)
Later you can check in any point the application
if (defined('WEBAPP')) {
echo "This is webapp";
} else {
echo "app was launched via console";
}
Checked in Yii 1.7
add a comment |
check Yii::$app->id
- when running from console Yii::$app->id = 'app-console'
- when running from frontend (browser) Yii::$app->id = 'app-frontend'
add a comment |
You can use
if(is_a(Yii::$app,'yiiconsoleApplication'))
for console, and
if(is_a(Yii::$app,'yiiwebApplication'))
for web.
https://stackoverflow.com/a/30635800/4916039
add a comment |
I am using Yii 1 and I use this function to check
public static function isWebRequest()
{
return Yii::app() instanceof CWebApplication;
}
public static function isConsoleRequest()
{
return Yii::app() instanceof CConsoleApplication; //!self::isWebRequest();
}
I put these functions in a helper(Componenet) Class and I use it as:
if(MyRandomHelper::isConsoleRequest())
{
Email::shoot();
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18148492%2fhow-to-check-if-a-yii-app-is-running-from-a-console-or-from-browser%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
Same way you would determine if a PHP application is being run in the console or not.
What is the canonical way to determine commandline vs. http execution of a PHP script?
Thanks, i thought there's a "YII-specific" function that i'm not aware of. Thanks again.
– zeratool
Aug 9 '13 at 14:36
add a comment |
Same way you would determine if a PHP application is being run in the console or not.
What is the canonical way to determine commandline vs. http execution of a PHP script?
Thanks, i thought there's a "YII-specific" function that i'm not aware of. Thanks again.
– zeratool
Aug 9 '13 at 14:36
add a comment |
Same way you would determine if a PHP application is being run in the console or not.
What is the canonical way to determine commandline vs. http execution of a PHP script?
Same way you would determine if a PHP application is being run in the console or not.
What is the canonical way to determine commandline vs. http execution of a PHP script?
edited May 23 '17 at 12:02
Community♦
11
11
answered Aug 9 '13 at 14:10
ethan
90257
90257
Thanks, i thought there's a "YII-specific" function that i'm not aware of. Thanks again.
– zeratool
Aug 9 '13 at 14:36
add a comment |
Thanks, i thought there's a "YII-specific" function that i'm not aware of. Thanks again.
– zeratool
Aug 9 '13 at 14:36
Thanks, i thought there's a "YII-specific" function that i'm not aware of. Thanks again.
– zeratool
Aug 9 '13 at 14:36
Thanks, i thought there's a "YII-specific" function that i'm not aware of. Thanks again.
– zeratool
Aug 9 '13 at 14:36
add a comment |
This reply is a bit late but there is a Yii-specific way to do this:
In Yii1 you can do:
if (Yii::app() instanceof CConsoleApplication)
In Yii2 that would be:
if (Yii::$app instanceof YiiconsoleApplication)
Hope that's useful to someone...
add a comment |
This reply is a bit late but there is a Yii-specific way to do this:
In Yii1 you can do:
if (Yii::app() instanceof CConsoleApplication)
In Yii2 that would be:
if (Yii::$app instanceof YiiconsoleApplication)
Hope that's useful to someone...
add a comment |
This reply is a bit late but there is a Yii-specific way to do this:
In Yii1 you can do:
if (Yii::app() instanceof CConsoleApplication)
In Yii2 that would be:
if (Yii::$app instanceof YiiconsoleApplication)
Hope that's useful to someone...
This reply is a bit late but there is a Yii-specific way to do this:
In Yii1 you can do:
if (Yii::app() instanceof CConsoleApplication)
In Yii2 that would be:
if (Yii::$app instanceof YiiconsoleApplication)
Hope that's useful to someone...
edited Feb 7 '17 at 10:40
answered Jul 13 '16 at 9:58
BlueZed
5951722
5951722
add a comment |
add a comment |
You should also be able to do:
echo get_class(Yii::app());
which will tell you what type of app you're in ...
add a comment |
You should also be able to do:
echo get_class(Yii::app());
which will tell you what type of app you're in ...
add a comment |
You should also be able to do:
echo get_class(Yii::app());
which will tell you what type of app you're in ...
You should also be able to do:
echo get_class(Yii::app());
which will tell you what type of app you're in ...
answered Aug 10 '13 at 1:58
acorncom
5,54411330
5,54411330
add a comment |
add a comment |
The most efficient way seems to define in the root file index.php this line :
define ('WEBAPP', true)
Later you can check in any point the application
if (defined('WEBAPP')) {
echo "This is webapp";
} else {
echo "app was launched via console";
}
Checked in Yii 1.7
add a comment |
The most efficient way seems to define in the root file index.php this line :
define ('WEBAPP', true)
Later you can check in any point the application
if (defined('WEBAPP')) {
echo "This is webapp";
} else {
echo "app was launched via console";
}
Checked in Yii 1.7
add a comment |
The most efficient way seems to define in the root file index.php this line :
define ('WEBAPP', true)
Later you can check in any point the application
if (defined('WEBAPP')) {
echo "This is webapp";
} else {
echo "app was launched via console";
}
Checked in Yii 1.7
The most efficient way seems to define in the root file index.php this line :
define ('WEBAPP', true)
Later you can check in any point the application
if (defined('WEBAPP')) {
echo "This is webapp";
} else {
echo "app was launched via console";
}
Checked in Yii 1.7
answered Jul 30 '15 at 6:49
Tebe
1,65742649
1,65742649
add a comment |
add a comment |
check Yii::$app->id
- when running from console Yii::$app->id = 'app-console'
- when running from frontend (browser) Yii::$app->id = 'app-frontend'
add a comment |
check Yii::$app->id
- when running from console Yii::$app->id = 'app-console'
- when running from frontend (browser) Yii::$app->id = 'app-frontend'
add a comment |
check Yii::$app->id
- when running from console Yii::$app->id = 'app-console'
- when running from frontend (browser) Yii::$app->id = 'app-frontend'
check Yii::$app->id
- when running from console Yii::$app->id = 'app-console'
- when running from frontend (browser) Yii::$app->id = 'app-frontend'
answered Feb 5 at 22:20
Petr Pánek
17115
17115
add a comment |
add a comment |
You can use
if(is_a(Yii::$app,'yiiconsoleApplication'))
for console, and
if(is_a(Yii::$app,'yiiwebApplication'))
for web.
https://stackoverflow.com/a/30635800/4916039
add a comment |
You can use
if(is_a(Yii::$app,'yiiconsoleApplication'))
for console, and
if(is_a(Yii::$app,'yiiwebApplication'))
for web.
https://stackoverflow.com/a/30635800/4916039
add a comment |
You can use
if(is_a(Yii::$app,'yiiconsoleApplication'))
for console, and
if(is_a(Yii::$app,'yiiwebApplication'))
for web.
https://stackoverflow.com/a/30635800/4916039
You can use
if(is_a(Yii::$app,'yiiconsoleApplication'))
for console, and
if(is_a(Yii::$app,'yiiwebApplication'))
for web.
https://stackoverflow.com/a/30635800/4916039
edited May 23 '17 at 12:02
Community♦
11
11
answered Jan 4 '17 at 12:31
Yasar Arafath
367623
367623
add a comment |
add a comment |
I am using Yii 1 and I use this function to check
public static function isWebRequest()
{
return Yii::app() instanceof CWebApplication;
}
public static function isConsoleRequest()
{
return Yii::app() instanceof CConsoleApplication; //!self::isWebRequest();
}
I put these functions in a helper(Componenet) Class and I use it as:
if(MyRandomHelper::isConsoleRequest())
{
Email::shoot();
}
add a comment |
I am using Yii 1 and I use this function to check
public static function isWebRequest()
{
return Yii::app() instanceof CWebApplication;
}
public static function isConsoleRequest()
{
return Yii::app() instanceof CConsoleApplication; //!self::isWebRequest();
}
I put these functions in a helper(Componenet) Class and I use it as:
if(MyRandomHelper::isConsoleRequest())
{
Email::shoot();
}
add a comment |
I am using Yii 1 and I use this function to check
public static function isWebRequest()
{
return Yii::app() instanceof CWebApplication;
}
public static function isConsoleRequest()
{
return Yii::app() instanceof CConsoleApplication; //!self::isWebRequest();
}
I put these functions in a helper(Componenet) Class and I use it as:
if(MyRandomHelper::isConsoleRequest())
{
Email::shoot();
}
I am using Yii 1 and I use this function to check
public static function isWebRequest()
{
return Yii::app() instanceof CWebApplication;
}
public static function isConsoleRequest()
{
return Yii::app() instanceof CConsoleApplication; //!self::isWebRequest();
}
I put these functions in a helper(Componenet) Class and I use it as:
if(MyRandomHelper::isConsoleRequest())
{
Email::shoot();
}
answered Nov 20 at 13:17
new_user
1,2651017
1,2651017
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18148492%2fhow-to-check-if-a-yii-app-is-running-from-a-console-or-from-browser%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown