i dont get why the new controller im making which is rendering a file in an action does not seem to have the same layout in content like yii generates automatically, the site/index, just like contact and about have their content a bit centered in the content, like some padding or margin, but when i make a new controller, it does look the same, looks a bit ugly being stick to the line where the content begins.
heres the new controller im making:
<?php
class ToolsController extends CController
{
// -----------------------------------------------------------
// Uncomment the following methods and override them if needed
/*
public function filters()
{
// return the filter configuration for this controller, e.g.:
return array(
'inlineFilterName',
array(
'class'=>'path.to.FilterClass',
'propertyName'=>'propertyValue',
),
);
}
public function actions()
{
// return external action classes, e.g.:
return array(
'action1'=>'path.to.ActionClass',
'action2'=>array(
'class'=>'path.to.AnotherActionClass',
'propertyName'=>'propertyValue',
),
);
}
*/
public function actionIndex()
{
$this->render('index');
}
}
and its just rendering this:
<h1>hello</h1>
im missing something?
sorry heres the layout:
<?php /* #var $this Controller */ ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="language" content="en" />
<!-- blueprint CSS framework -->
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/dist/css/bootstrap.css">
<!--[if lt IE 8]>
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/ie.css" media="screen, projection" />
<![endif]-->
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/main.css" />
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/form.css" />
<title><?php echo CHtml::encode($this->pageTitle); ?></title>
</head>
<body>
<div class="container" id="page">
<div id="header">
<div id="logo"><?php echo CHtml::encode(Yii::app()->name); ?></div>
</div><!-- header -->
<div id="mainmenu">
<?php $this->widget('zii.widgets.CMenu',array(
'htmlOptions'=>array('class'=>'nav nav-pills'),
'items'=>array(
array('label'=>'Home', 'url'=>array('/site/index')),
array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),
array('label'=>'Contact', 'url'=>array('/site/contact')),
array('label'=>'Tools', 'url'=>array('/tools/index')),
),
)); ?>
</div><!-- mainmenu -->
<?php if(isset($this->breadcrumbs)):?>
<?php $this->widget('zii.widgets.CBreadcrumbs', array(
'links'=>$this->breadcrumbs,
)); ?><!-- breadcrumbs -->
<?php endif?>
<?php echo $content; ?>
<div class="clear"></div>
<div id="footer">
Copyright © <?php echo date('Y'); ?> by My Company.<br/>
All Rights Reserved.<br/>
<?php echo Yii::powered(); ?>
</div><!-- footer -->
</div><!-- page -->
</body>
</ht
ml>
Quick fix is:
public $layout='//layouts/myLayout';
Pretty sure you can also set it in the Base Controller also
Related
It displays but doesn't work button click.
Index.cshtml:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="~/lib/bootstrap/css/bootstrap.css">
</head>
<body>
<component type="typeof(ShiftsEditor)" render-mode="WebAssemblyPrerendered"/>
</body>
</html>
ShiftsEditor.razor (it is the test component):
#page "/ShiftsEditor"
<h3>ShiftsEditor</h3>
<p>#prgf</p>
<button #onclick="UpdateHeading">button</button>
#code {
public string prgf = "str";
public void UpdateHeading() => prgf = "content updated";
}
You can check if the JS you are referencing in _Layout.cshtml is <script src="_framework/blazor.server.js"></script> or
<script src="_framework/blazor.webassembly.js"></script>.
server.js needs to use render-mode="ServerPrerendered", and webassembly.js needs to use render-mode="WebAssemblyPrerendered".
Index.cshtml:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="~/lib/bootstrap/css/bootstrap.css">
</head>
<body>
<component type="typeof(ShiftsEditor)" render-mode="ServerPrerendered"/>
</body>
</html>
Add#using Microsoft.AspNetCore.Components and #using Microsoft.AspNetCore.Components.Web in razor.
ShiftsEditor.razor:
#page "/ShiftsEditor"
#using Microsoft.AspNetCore.Components
#using Microsoft.AspNetCore.Components.Web;
<h3>ShiftsEditor</h3>
<p>#prgf</p>
<button #onclick="UpdateHeading">button</button>
#code {
public string prgf = "str";
public void UpdateHeading() => prgf = "content updated";
}
_Layout.cshtml:
<base href="~/" />
<script src="_framework/blazor.server.js"></script>
Program:
builder.Services.AddServerSideBlazor();
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
}
Test Result:
Before click:
After click:
Hey guys i'm using asp mvc4 for building a site,im having trouble in Views
First of all i have my _Layout View calling a partialView for header and my partial View is getting data from a model in to fill some data in the header,
It's working by the way just in the Main (index) view but moving to another views just call the Partial view without getting data from database.
Hope i explained Well :D
_layout View
#model MvcApplication1.Models.SchoolInfo
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>#Html.DisplayFor(model => model.SiteName)</title>
<!-- Bootstrap Core CSS -->
<link href="~/Content/Template/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="~/Content/Template/css/business-casual.css" rel="stylesheet">
<!-- Fonts -->
<link href="http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Josefin+Slab:100,300,400,600,700,100italic,300italic,400italic,600italic,700italic" rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<body>
<header>
<section id="login">
#Html.Partial("_LoginPartial")
#if (Request.IsAuthenticated)
{
#Html.Partial("_SiteHeaderPartial")
}
</section>
</header>
#RenderBody()
#if (Request.IsAuthenticated){
<footer>
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<p>Copyright © Your Website footer</p>
</div>
</div>
</div>
</footer>
}
<!-- jQuery -->
<script src="~/Scripts/Template/js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="~/Scripts/Template/js/bootstrap.min.js"></script>
<!-- Script to Activate the Carousel -->
<script>
$('.carousel').carousel({
interval: 5000 //changes the speed
})
</script>
_SiteHeaderPartial
#model MvcApplication1.Models.SchoolInfo
<div class="brand">#Html.DisplayFor(model => model.SchoolName)</div>
<div class="address-bar">Country | Address : #Html.DisplayFor(model => model.SchoolAddress) | 011 #Html.DisplayFor(model => model.SchoolPhone)
Index and About views are the same (empty).
If your not seeing the details in the About.cshtml view, its because you have not passed a SchoolInfo model to that view (or the model is not populated with the data). However a layout should not include a model declaration (unless its a base model from which all views that use that layout derive).
Remove #model MvcApplication1.Models.SchoolInfo from the layout and instead of #Html.Partial("_SiteHeaderPartial"), use
#Html.Action("SiteHeader", "yourControllerName")
where SiteHeader() is a a controller method that gets your data and returns a partial view, for example
[ChildOnlyAction]
public PartialViewResult SiteHeader()
{
SchoolInfo model = ... // populate your model
return PartialView("_SiteHeaderPartial", model);
}
Sife note: You also need to remove <title>#Html.DisplayFor(model => model.SiteName)</title> or replace it with (say) <title>#ViewBag.Title</title> and in each view, pass the value to the partial using #{ ViewVag.Title = someValue; }
I have this code that I want that $X to be updated in the form, so when I press the +1 button it just keep going adding 1 to the form
<html>
<head>
<title>7mada</title>
</head>
<body>
<?php $X = 7 ;?>
<form method="POST" >
<table border="0" width="60%">
<tr> <td width ="30%"> Number: </td><td><input type="test" name="newname" value="<?php echo $X ;?>" readonly></td></tr>
</table>
<input name="save" type="submit" value="+1"/>
</form>
<?php
if($_POST){
if($_POST['save'] == "+1"){
$_POST['newname']++;
echo $_POST['newname'];
$X = $_POST['newname'];
}
}else{echo "say smth";}
?>
</body>
</html>
thanks.
Hey Samy this is the answer for your question :D :D
It completely ignores HTML output, therefore PHP can't interact with events that should be javascript.
you have two options:
1-Do it in Javascript, Live
2-Do it in PHP, requires refresh
If you want to do it in JavaScript, you'd do this:
<html>
<body>
<button onclick="add()">Add</button>
<div id="showIt"><script type="text/javascript">document.write(x);</script></div>
</body>
<head>
<title></title>
<script type="text/javascript">
var x = 0;
function add() {
x++;
document.getElementById('showIt').innerHTML = x;
}
</script>
</head>
</html>
or in PHP:
<?php
session_start();
$_SESSION['x'] = ((isset($_SESSION['x'])) ? $_SESSION['x'] : 0);
if(isset($_GET['add'])){
$_SESSION['x']++;
}
?>
<html>
<head>
<title></title>
</head>
<body>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="get">
<input type="submit" name="add" value="add" />
</form>
<?php
echo $_SESSION['x'];
?>
</body>
</html>
I hope this helps you,
Mahmoud Elsaadany
how get parameters from compose() in view Yii-2?
I try:
/controllers/SiteController
Yii::$app->mailer->compose('layouts/html.php', ['model' => 'trtrtrtrt',])
->setFrom('ergegergerger#gmail.com')
->setTo('ergergergegerg#mail.ru')
->setSubject('TEST')
->send();
mail/layouts/html.php
<?php
use yii\helpers\Html;
use yii\mail\BaseMailer;
/* #var $this \yii\web\View view component instance */
/* #var $message \yii\mail\MessageInterface the message being composed */
/* #var $content string main view render result */
?>
<?php $this->beginPage() ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?= Yii::$app->charset ?>" />
<title><?= Html::encode($this->title) ?>Тестовое письмо</title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div style="background-color: green;">Приветик !</div>
<?= Html::encode($model) ?>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
i get error "Undefined variable: model" - <?= Html::encode($model) ?>
how get parameters from compose()?
You are calling a parameter in the layout file. But the parameter model is available only in the view.
So you have to change the code:
mail/layouts/html.php
<?php
use yii\helpers\Html;
use yii\mail\BaseMailer;
/* #var $this \yii\web\View view component instance */
/* #var $message \yii\mail\MessageInterface the message being composed */
/* #var $content string main view render result */
?>
<?php $this->beginPage() ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?= Yii::$app->charset ?>" />
<title><?= Html::encode($this->title) ?>Тестовое письмо</title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div style="background-color: green;">Приветик !</div>
<?= $content ?>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
mail/emailview.php
<?= Html::encode($model) ?>
php code
Yii::$app->mailer->compose('emailview.php', ['model' => 'trtrtrtrt',])
->setFrom('ergegergerger#gmail.com')
->setTo('ergergergegerg#mail.ru')
->setSubject('TEST')
->send();
It's very strange, I call dijit.byId() in dojo.addOnLoad(function{...}), it return undefined. In order to check if the id exist, i call dojo.byId() at the same time, it return some object. So I guess the component is not a dijit component? this is the whole code: Please help me, thanks in advice!
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<!-- Dojo/Diji definations -->
<link href='../dojoroot/dijit/themes/tundra/tundra.css' type='text/css' rel='stylesheet'/>
<link href='../dojoroot/dojo/resources/dojo.css' type='text/css' rel='stylesheet'/>
<script type="text/javascript" src="../dojoroot/dojo/dojo.js" djConfig="parseOnLoad: true"></script>
<!-- Main scripts -->
<script type="text/javascript">
dojo.addOnLoad(function()
{
// Include library
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.TabContainer");
dojo.require("dijit.layout.ContentPane");
// add the select child event to the tab panel
alert(dijit.byId("contentTabPanel")); // return no defined
alert(dojo.byId("contentTabPanel")); // return an object
});
</script>
</head>
<body class="tundra">
<div dojoType="dijit.layout.BorderContainer" style="width: 100%; height: 100%;">
<!-- Content Tab Panel -->
<div id="contentTabPanel" dojoType="dijit.layout.TabContainer" region="center">
<!-- Tab UserGroup -->
<div dojoType="dijit.layout.ContentPane" title="UserGroup">
</div>
</div>
</div>
</body>
</html>
OMFG!!!!! I know the reason!!!!! I cost 5 Hours just for this STUPID error:
I MUST write the
// Include library
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.TabContainer");
dojo.require("dijit.layout.ContentPane");
outside the dojo.addOnLoad(function() { !!!